0

我有一个 div:

#content_wrapper { 
    position: absolute;
    left: 0px;
    height: 50px; 
    width: 50px;
    background-color: red;
}

我想要.animate()一个 div from left: 0pxtoright: 0px所以我的尝试是:

$('#content_wrapper').animate({'right': 0, 'left':''}, 2000, "easeOutBounce");

此外我试过

$('#content_wrapper').animate({'right': 0, 'left': 'auto'}, 2000, "easeOutBounce");

你猜怎么着,没用。

有什么建议么?谢谢

4

2 回答 2

0

您可以按照评论中的建议使用绝对值。例如,如果您的 div 绝对位于其直接父级中,则如下所示:

var w = $('#content_wrapper')
w.animate({"left": (w.parent().width()-w.width())+"px"}, 2000);
于 2013-11-02T22:35:21.063 回答
0

这是一个小提琴

<div id="content_wrapper"></div>

#content_wrapper { 
  position: absolute;
  left: 0;
  height: 50px; 
  width: 50px;
  background: red;
}

$(function() {
  $('#content_wrapper').animate({ left: $(window).innerWidth() - 50 + 'px' }, 2000, 'easeOutBounce');
});
于 2013-11-03T15:25:00.287 回答