This article describes the method of implementing the timed roll effect of JS image. 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>Image rolling up 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/// Parameters: o Scroll block object/// Parameters: d Height for each scrolling/// Parameters: 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 the problem that spaces are returned as nodes in firefox function getFirstChild(node){ while (node.nodeType != 1) { node = node.nextSibling; } return node; } </script> </head> <body> Scroll timing effect demonstration<hr> <div> <div id="box"> <div> <img src="../img/head/1.png"/> </div> <div> <img src="../img/head/2.png"/> </div> <div> <img src="../img/head/3.png"/> </div> <div> <img src="../img/head/4.png"/> </div> </div> </div> </body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.