手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS图片定时翻滚效果实现方法
JS图片定时翻滚效果实现方法
摘要:本文实例讲述了JS图片定时翻滚效果实现方法。分享给大家供大家参考,具体如下:图片向上翻滚效果.father{position:relativ...

本文实例讲述了JS图片定时翻滚效果实现方法。分享给大家供大家参考,具体如下:

<!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>图片向上翻滚效果</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) } ///滚动主方法 ///参数:o 滚动块对象 ///参数:d 每次滚屏高度 ///参数:c 当前已滚动高度 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); } } //解决firefox下会将空格回车作为节点的问题 function getFirstChild(node){ while (node.nodeType != 1) { node = node.nextSibling; } return node; } </script> </head> <body> 滚动定时效果演示 <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>

希望本文所述对大家JavaScript程序设计有所帮助。

【JS图片定时翻滚效果实现方法】相关文章:

JavaScript实现鼠标点击后层展开效果的方法

JavaScript判断数组是否包含指定元素的方法

Javascript实现飞动广告效果的方法

精彩图片推荐 渐隐渐现

JQuery分屏指示器图片轮换效果实例

javascript搜索框效果实现方法

JavaScript模版引擎的基本实现方法浅析

JS+DIV实现鼠标划过切换层效果的方法

jQuery实现返回顶部效果的方法

JS动画效果打开、关闭层的实现方法

精品推荐
分类导航