使用jQuery实现marginLeft动画效果

23

我无法弄清如何使用jQuery使marginLeft动画化。每当用户单击链接时,我需要它减去938px,当我使用 .css() 时可以正常工作,但是我不知道如何使用 .animate() 来使其正常工作。

$("#full-wrapper #full").animate({
    marginLeft, -=938px
}, 500);

有人可以想出为什么这不起作用吗?这是我的 CSS 版本:

$("#full-wrapper #full").css("marginLeft","-=938px");

我之前使用CSS3实现动画,但需要让它在旧版浏览器中正常工作。

3个回答

49

你的代码存在语法错误,因为在向 animate() 传递参数时,你应该使用:而不是,来分隔每个属性。尝试这样做:

$("#full-wrapper #full").animate({
    marginLeft: '-=938px'
}, 500);

示例代码


3

将逗号(,)替换为冒号(:)。

$("#full-wrapper #full").animate({
    marginLeft: "-=938px"
}, 500);

1
$("#full-wrapper #full").animate({
    marginLeft: '-=938px'
}, 500);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接