首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一旦满足特定条件就停止动画- Jquery

一旦满足特定条件就停止动画- Jquery
EN

Stack Overflow用户
提问于 2013-06-27 20:21:05
回答 1查看 270关注 0票数 0

我想停止动画滚动一旦它符合特定的条件。

这是我的

代码语言:javascript
复制
var $box2 = $('.column'),
    Width = max_x,
    cursor = 0;
var Width = $("#column").width();
console.log(divWidth)


$("#right-button").click(function () {
    if (cursor != Width && Width >= divWidth) {
        $box2.animate({
            marginLeft: "-=100"
        }, "fast");

        cursor += 300;
    }
});

我正在动画滚动到-或r +300取决于点击。我想在这里写一个条件,比如当前宽度大于总宽度,停止动画。

已尝试使用if cursor != totalWidth && totalWidth >= divWidth && this.width > totalWidth,但不起作用。如何在动画中找到当前的宽度?我应该在这里做什么?

EN

回答 1

Stack Overflow用户

发布于 2013-06-27 20:35:26

尝试使用步骤回调:

代码语言:javascript
复制
$box2.animate({
    marginLeft: "-=100"
}, {
    step: function (now, fx) {
        if (cursor != totalWidth && totalWidth >= divWidth) $(this).stop();
    }
}, "fast");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17343011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档