SoFunction
Updated on 2025-04-07

js implements rotating dice model

This article creates a model that automatically generates dice numbers randomly. Because you need to introduce pictures, you will save the picture here. You can import the picture yourself to verify the code.

<!DOCTYPE html>
<html>
  <head>

    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
    <!--Create an object-->
    <div >
      <img src="img/img/" />
    </div>
    <div >
      <img src="img/img/" />
    </div>
  <div >
    <img src="img/img/" />
  </div>
    <input type="button" value="start"  onclick="tst()"/>
    <input type="button" value="stop"  onclick="stop()"/>
    <script type="text/javascript">
    //First get the object and declare a global variable, leaving it to the setTimeout() function to use    var bt1=("button1");
    var bt2=("button2");
    var ims=("img");
    var a;
    //The function to start    function tst(){
      var num=(()*6+1)
      for (var i=0;i<3;i++) {
        ims[i].src="img/img/sai"+num+".png";
      }a=setTimeout(tst,500);
      //After clicking once, clicking again has no effect      ("onclick")
    }
    function stop(){
      clearTimeout(a)
      //After clicking once, reply to the function of the start button      ("onclick","tst()")
    }
    </script>
  </body>
</html>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.