![](/img/trans.png)
[英]How to animate position absolute from right to left and then left to right in jQuery?
[英]How to animate a Div from left to current position
伙计们,我正在尝试将汽车从左移到DIV的当前位置。
这是JSFiddle
码
setTimeout(function(){
var pos = $('#parentx').offset() - ('.car1').offset() ;
$(".car1").animate({left: pos}, 2000);
}, 1000);
你有车设置一些默认的位置(只是改变了left
css中值),然后检查左侧偏移.car1 parent
和动画的left
到该值。
function moveCar() {
var newPos = $(".car1").parent().offset().left;
$('.car1').animate({left: newPos + "px"}, 2000);
}
见小提琴
尝试这个。 它将起作用:)
div.car1
{
transition:2s;
-webkit-transition:2s;
-moz-transition:2s;
position:absolute;
right:calc(100% - 100px);
}
div.car1:hover
{
right:0px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.