本效果使用js实现,当图片移动到200像素后回到0像素再向右移动200像素一直左右移动,不需要marquee标签。
完整的HTML代码如下,保存到HTML文档打开可以查看效果:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>JS使图片左右移动_何问起</title> <meta charset="utf-8" /> <base target="_blank" /> <style>a{color:blue;}</style> </head> <body> <p>mag:</p><input type="text" /><br /> <input type="button" value="开始" />请点击按钮<br /> <div> <img src="https://hovertree.com/themes/hvtimages/hlogo.png" /> </div> <div><a href="https://hovertree.com/h/bjaf/62ak7aig.htm">查看代码</a> <a href="https://hovertree.com">返回首页</a> <a href="https://hovertree.com/texiao/">更多特效</a></div> <script> var hovertreeStep, hovertreeTurn = true; function move() { var mag = parseInt(document.getElementById("img").style.left); document.getElementById("pos").value = mag; if (hovertreeTurn) { hovertreeStep = 1; hovertreeTurn = false; } if ( mag > 200) { hovertreeStep = -1; } if (mag < 1) { hovertreeStep = 1; } document.getElementById("img").style.left = (mag + hovertreeStep) + "px"; window.setTimeout("move()", 50); } </script> </body> </html>