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/
精彩评论