Implementation method of timed rollover effect for JS pictures

  • 2021-06-29 09:55:51
  • OfStack

This paper gives an example of how to achieve the timed rollover effect of JS pictures.Share it for your reference, as follows:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=7" />
  <title> Picture rollup effect </title>
  <style type="text/css">
  *  .father{
  * position:relative;
  *  overflow:hidden;
  *  height:100px;
  *  width:300px;
  *  }
   .box {
    float: left;
    font-size: 12px;
    width: 80px;
    height: 120px;
    overflow: hidden;
  * position:absolute;
   }
  </style>
  <script language="javascript" type="text/javascript">
   var t;
   window.onload = function(){
    var o = document.getElementById('box');
    t = window.setInterval(function(){
     scrollup(o, 24, 0);
    }, 3000)
   }
   /// Scroll Main Method 
   /// parameter :o  Scroll Block Object 
   /// parameter :d  Height of each scroll 
   /// parameter :c  Current Scrolled Height 
   function scrollup(o, d, c){
    if (d == (c - 78 )) {
     var t = getFirstChild(o.firstChild).cloneNode(true);
     o.removeChild(getFirstChild(o.firstChild));
     o.appendChild(t);
     t.style.marginTop = "0px";
    }
    else {
     c += 1;
     getFirstChild(o.firstChild).style.marginTop = -c + "px";
     window.setTimeout(function(){
      scrollup(o, d, c)
     }, 15);
    }
   }
   // Solve firefox Next will be the question of returning blanks as nodes 
   function getFirstChild(node){
    while (node.nodeType != 1) {
     node = node.nextSibling;
    }
    return node;
   }
  </script>
 </head>
 <body>
   Rolling timer effect demonstration 
 <hr>
 <div class="father">
   <div id="box">
    <div class="item">
     <img src="../img/head/1.png"/>
    </div>
    <div class="item">
     <img src="../img/head/2.png"/>
    </div>
 <div class="item">
     <img src="../img/head/3.png"/>
    </div>
 <div class="item">
     <img src="../img/head/4.png"/>
    </div>
   </div>
 </div>
 </body>
</html>

More readers interested in JavaScript related content can view this site's topics: JavaScript Switching Special Effects and Techniques Summary, JavaScript Finding Algorithmic Techniques Summary, JavaScript Animation Special Effects and Techniques Summary, JavaScript Errors and Debugging Techniques Summary, JavaScript Data Structure and Algorithmic Techniques Summary,Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Operation Usage

I hope that the description in this paper will be helpful to everyone's JavaScript program design.


Related articles: