简体   繁体   English

Jquery动画从左到右不起作用

[英]Jquery Animation Left to right not working

Why is this not working? 为什么这不起作用? This should be animate the arrow from left to right and then back to left again and so on, but this is not working. 这应该是从左到右,然后再从左到右依次为箭头设置动画,依此类推,但这不起作用。 Why is that? 这是为什么?

 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>&nbsp; Go Back </a> 

Add style position:absolute to the icon 添加样式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>&nbsp; Go Back </a> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM