为什么这不起作用?这应该是从左到右,然后再从左到右依次为箭头设置动画,依此类推,但这不起作用。那是为什么?
function moveRight(){
$('#myIcon').animate({left: "+=50"}, 1000, function(){
$('#myIcon').animate({left: "-=50"}, 1000, moveRight)
})
}
moveRight();

a{
text-decoration: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" class="btn btn-danger btn-lg">
<span id="myIcon">←</span> Go Back
</a>
&#13;
答案 0 :(得分:7)
将样式position:absolute
添加到图标
function moveRight(){
$('#myIcon').animate({left: "+=50"}, 1000, function(){
$('#myIcon').animate({left: "-=50"}, 1000, moveRight)
})
}
moveRight();
a{
text-decoration: none;
}
#myIcon{
position:absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" class="btn btn-danger btn-lg">
<span id="myIcon">←</span> Go Back
</a>