javascript - JQuery CSS 动画

标签 javascript jquery css animation

我无法让这个动画正常工作。

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

我将 div 向左滑动 470px,跳到 620px 并向左滑动另一个 470px。 $(this).css({ "marginLeft": "620px"似乎不起作用。

初始 margin-left 为 150px。运行脚本后它是-790px。 (150-470-470)。

最佳答案

首先,你有语法错误:

$("#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");

演示:http://jsfiddle.net/mattball/j7rcr/

关于javascript - JQuery CSS 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557351/

相关文章:

css - 使用 $q.all 处理多个 ajax 调用

javascript - 在除我的索引之外的所有页面上收到 'Uncaught TypeError: Cannot read property ' addEventListener' of null' ?

javascript - 从单独的 gulp 文件导入/读取变量

javascript - jQuery 表单验证检查以循环结束

javascript - Bootstrap-table showAllColumns 方法

jquery - 使用 Jquery 的背景 PNG 图像 - 悬停 IE6 问题

javascript - jQuery 中有类似 "listenTo"的东西吗?或者我是否必须使用命名空间并手动取消绑定(bind)?

css - twitter bootstrap 有屏和无屏的区别

jquery - 通过使用 jQuery 单击 anchor 来平滑滚动元素

javascript - 原生 Office 命令的 Word 功能区自定义