meta charset="UTF-8"> title>Custom animation title> script type="text/javascript" src="jquery.1.12."/> meta charset="UTF-8"> title>Custom animation title> script type="text/javascript" src="jquery.1.12.">
Home > Article > Web Front-end > How to move pictures left and right using javascript
The left and right movement of the picture has an animation effect like a swing. The picture itself can be redefined, and the moving speed and distance can also be set in the code. It is a very simple Js-generated animation special effects code. ,for reference only.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>自定义动画</title> <script type="text/javascript" src="jquery.1.12.4.js"></script> <style> * { margin: 0; } </style> <script type="text/javascript"> var moveToLeft = function () { $("#topImg").animate( { "left": "0" } , "slow", moveToRight); } ; var moveToRight = function () { $("#topImg").animate( { "left": "100px" } , "slow", moveToLeft); } ; $(function () { $("button").click(moveToRight); } ); </script></head><body><button>点击我右移100px</button><br/><br/><br/><br/><img id="topImg" style="position: absolute; left: 0" src="图片1_30.jpg"/></body></html>
The above is the detailed content of How to move pictures left and right using javascript. For more information, please follow other related articles on the PHP Chinese website!