SoFunction
Updated on 2025-04-02

Native JS implements left and right picture carousels

This effect is implemented using js. When the image moves to 200 pixels, it returns to 0 pixels and then moves to the right by 200 pixels and moves left and right, and does not require a marquee tag.

The complete HTML code is as follows. Save it to the HTML document to open it to view the effect:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>JSMove the picture left and right_Why ask</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" onclick="move()" value="start" />Please click on the button<br />
  <div style="position:relative;min-width:600px;min-height:120px;">
    <img  style="position:absolute; left:100px;" src="/themes/hvtimages/" />
  </div>
  <div><a href="/h/bjaf/">View the code</a> <a href="">Return to homepage</a> <a href="/texiao/">More special effects</a></div>
  <script>
    var hovertreeStep, hovertreeTurn = true;
    function move() {
      var mag = parseInt(("img").);
      ("pos").value = mag;
      
      if (hovertreeTurn) {
        hovertreeStep = 1; hovertreeTurn = false;
      }
      if ( mag > 200) {
        hovertreeStep = -1;
      }
      if (mag < 1)
      {
        hovertreeStep = 1;
      }

      ("img"). = (mag + hovertreeStep) + "px";
      ("move()", 50);
    }
  </script>
</body>
</html>

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!