图片的左右移动,具备像荡秋千一样的动画效果,图片自己可重新定义,移动速度和距离也可在代码内设定,挺简单的js生成动画的特效代码,仅供参考。
<!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实现图片左右移动的方法的详细内容。