开发者

JQuery CSS Animation

I am having trouble getting this animation to work.

$("#selectedTime").stop().animate({
    "margin-left": "-=470px"
},"fast", function() {
    $(this).css({ "margin-left": "620px"
})}).animate({
    "margin-left": "-=470px"
},"fast");

I am sliding the div to the left 470px, jumping to 620px and sliding another 470px to the left. $(this).css({ "marginLeft": "620px" does not seem to be working.

The initial ma开发者_如何学运维rgin-left is 150px. After running the script it is -790px. (150-470-470).


To start, you've got syntax errors:

$("#selectedTime").stop().animate({
    "margin-left": "-=470px"
},"fast", function() {              // ↓↓↓ here 
    $(this).css({ "margin-left": "620px"}); 
}).animate({
    "margin-left": "-=470px"
},"fast");

$("#selectedTime")
    .stop()
    .animate({"margin-left": "-=470px"}, "fast")
    .animate({"margin-left": "620px"}, 0)
    .animate({"margin-left": "-=470px"}, "fast");

Demo: http://jsfiddle.net/mattball/j7rcr/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜