<!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>
以上就是javascript实现图片左右移动的方法的详细内容。
