【问题标题】:jQuery mouse queue/ css change problemjQuery 鼠标队列/ css 更改问题
【发布时间】:2010-09-17 19:14:42
【问题描述】:
$(next).click(function(event) {
    event.preventDefault();

    if(parseInt($(container).css('left')) <= (-(container_width-offset))) {
        $(container).animate({
                queue:false,
                left: "0px"
            }, speed, function() {

            });

    } else {
        $(container).animate({
                queue:false,
                left: "-="+offset+"px"
        }, speed, function() { });
    }
});

前面的代码动画一系列浮动的 div 从左向右滑动。一切正常,除非有人点击鼠标太快,css 更新不够快,有时它会滚动到空白 div,因为此行注册速度不够快: parseInt($(container).css('left')) &lt;= (-(container_width-offset))

我该如何解决这个问题?

【问题讨论】:

    标签: jquery css


    【解决方案1】:

    添加这一行

    if($(this).is(":animated")) return;
    

    (在event.preventDefault();之后)

    【讨论】:

    • 那是光荣的。它在做什么?
    • 如果元素是“动画”则退出该函数,这意味着它当前正在移动/淡入淡出/无论什么
    猜你喜欢
    • 2012-07-14
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 2011-03-22
    • 2015-09-23
    • 1970-01-01
    相关资源
    最近更新 更多