0
我试图使用jquery easing(请参阅http://gsgd.co.uk/sandbox/jquery/easing/)动画图像,这将允许 图像从右到左点击链接('费率'的情况下)在导航栏上飞行。问题是,我无法 重置图像的左边距,因此如果我不止一次点击,每次点击 时,图像都会移动。我尝试像initalLeftMargin = initalLeftMargin + 285;
为了重置边距。但是,没有运气。 任何建议,非常感谢。如何使用jquery easing重置动画图片的边距?
JS
$("#section-rates-go").click(function goRightEase(){
var initalLeftMargin = $(".innerLiner").css('margin-left').replace("px", "")*1;
var newLeftMargin = (initalLeftMargin - 285); // extra 2 for border
$(".innerLiner").animate({ marginLeft: newLeftMargin }, 4000, 'easeOutBounce');
})
CSS
.animation-mycontainer{
Box-sizing: Border-box;
white-space: nowrap;
overflow-x: hidden;
width: 280px;
}
.animation-box{
Box-sizing: Border-box;
display:inline-block;
width: 278px;
height: 148px;
vertical-align:top;
background-color:white;
}
HTML 导航栏marhup:
<ol class="nav navbar-nav navbar-right text-right">
<li>
<a href="#section-home">
<span>Home</span></a></li>
<li>
<a href="#section-services">
<span >Services</span></a></li>
<li>
<a href="#section-rates-go" class="section-rates-go">
<span>Rates</span></a></li>
<ol>
动画标记:
</span>
<span class="animation-box">
<img src="./Content/img/car-big1.jpg" width="270"/>
</span>
</div>
</div>