我想停止动画滚动一旦它符合特定的条件。
这是我的
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,但不起作用。如何在动画中找到当前的宽度?我应该在这里做什么?
发布于 2013-06-27 20:35:26
尝试使用步骤回调:
$box2.animate({
marginLeft: "-=100"
}, {
step: function (now, fx) {
if (cursor != totalWidth && totalWidth >= divWidth) $(this).stop();
}
}, "fast");https://stackoverflow.com/questions/17343011
复制相似问题