2013-11-02 135 views
0

我有一个div:删除CSS属性()

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

我想.animate()left: 0px一个div来right: 0px所以我的尝试是:

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

而且我试过

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

猜猜看,没有工作。

有什么建议吗?谢谢

+0

一般不是好主意,左,右位置应用到元素特别是对动画 – charlietfl

+1

@ charlietfl你为什么这么说?只要元素是'position:absolute',我不会看到问题 –

+0

@charlietfl那么请给我一个建议,如何为每个窗口大小从左到右设置动画元素,而无需进行偏移量计算? – supersize

回答

0

您可以使用评论中建议的绝对值。例如像这样的,如果你的DIV绝对定位在其直接父:

var w = $('#content_wrapper') 
w.animate({"left": (w.parent().width()-w.width())+"px"}, 2000); 
0

这里有一个Fiddle

<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'); 
});