动画scrollTop触发滚动事件 [英] animate scrollTop fires scroll event

查看:186
本文介绍了动画scrollTop触发滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以监听一个页面的滚动,它负责两件事情,当页面发生变化时执行必要的操作(它可以工作),还可以将scrollTop动画化为最近的页面,但是这样做,滚动事件被触发,所以它顺序地爬过所有的页面,直到它到达文档的末尾。

I have some code that listens to the scrolling of a page and it's responsible for two things, performing the necessary action (which works) when the "page" has changed but also animate the scrollTop to the nearest "page" but in doing so the scroll event is fired so it sequentially crawls through all the "pages" until it reaches the end of the document.

我如何停止动画scrollTop触发滚动事件?甚至可能吗?

How can I stop animate scrollTop from firing the scroll event? Is it even possible?

页面因为这是一个iPad html页面,每个1024x768视图是一个页面

"pages" because this is an iPad html page and each 1024x768 view is a "page"

推荐答案

您可以在这篇文章中找到答案: https://stackoverflow.com/a/1659231/237838

You can find a answer at this post : https://stackoverflow.com/a/1659231/237838


您可以编写自己的代码来设置动画值,并设置
a标志,表示更改来自动画。

You could make write your own code to set the animation value, and set a flag indicating that the change comes from an animation.

例如:(未验证)

var scrollAnimating = false
jQuery.fx.step.scrollTop = function(E) {
    scrollAnimating = true;
    E.elem.scrollTop = E.now;
    scrollAnimating = false;
};

$('#gototop').click(function() {
    $('body').animate({scrollTop:0},3000);
    $(window).scroll(function () {
        if (!scrollAnimating)
            $('body').stop();
    });
    return false;
})


这篇关于动画scrollTop触发滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆