Jquery 删除动画()上的css属性

Jquery 删除动画()上的css属性,jquery,html,css,Jquery,Html,Css,我有一个部门: #content_wrapper { position: absolute; left: 0px; height: 50px; width: 50px; background-color: red; } 我想要.animate()从左:0px到右:0px的div,所以我的尝试是: $('#content_wrapper').animate({'right': 0, 'left':''}, 2000, "easeOutBounce");

我有一个部门:

#content_wrapper { 
    position: absolute;
    left: 0px;
    height: 50px; 
    width: 50px;
    background-color: red;
}
我想要
.animate()
左:0px
右:0px
的div,所以我的尝试是:

$('#content_wrapper').animate({'right': 0, 'left':''}, 2000, "easeOutBounce");
而且我试过了

$('#content_wrapper').animate({'right': 0, 'left': 'auto'}, 2000, "easeOutBounce");
你猜怎么着,我没用


有什么建议吗?谢谢

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

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


#内容包装{
位置:绝对位置;
左:0;
高度:50px;
宽度:50px;
背景:红色;
}
$(函数(){
$('content_wrapper')。动画({left:$(window.innerWidth()-50+'px'},2000,'easeOutBounce');
});

通常情况下,对元素应用左右位置不是一个好主意,尤其是对于animation@charlietfl你为什么这么说?只要元素是
position:absolute
我就看不到issue@charlietfl那么,请给我一个建议,如何在不计算偏移量的情况下,从左到右为每个窗口大小的元素设置动画?jQuery无法设置从
left:0
right:0
的直接路径。您需要从
left:0
left:100%
left:someValue
设置动画,以便jQuery可以插入中间值positions@RoryMcCrossan考虑流体容器大约1000 px…想要孩子200px宽…如何设置左和右的绝对值?甚至百分之十。必须将其中一个更改为
inherit
<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');
});