JS简单实现无缝滚动效果实例_Javascript教程-查字典教程网
JS简单实现无缝滚动效果实例
JS简单实现无缝滚动效果实例
发布时间:2016-12-30 来源:查字典编辑
摘要:本文实例讲述了JS简单实现无缝滚动效果。分享给大家供大家参考,具体如下:javascript无缝滚动h1{font:40016px/1"Mi...

本文实例讲述了JS简单实现无缝滚动效果。分享给大家供大家参考,具体如下:

<!doctype html> <title>javascript无缝滚动</title> <meta charset="utf-8" /> <meta name="keywords" content="javascript无缝滚动" /> <meta name="description" content="javascript无缝滚动" /> <style type="text/css"> h1 { font: 400 16px/1 "Microsoft YaHei", KaiTi_GB2312, SimSun } #marquee { position: relative; width: 400px; overflow: hidden; border: 10px solid #8080C0; } #marquee img { border: 0px; } #marquee dl, #marquee dt, #marquee dd, #marquee a { float: left; margin: 0; padding: 0; } #marquee dl { width: 1000%; height: 150px; } </style> <script type="text/javascript"> var Marquee = function(id) { try { document.execCommand("BackgroundImageCache", false, true); } catch(e) {}; var container = document.getElementById(id), original = container.getElementsByTagName("dt")[0], clone = container.getElementsByTagName("dd")[0], speed = arguments[1] || 10; clone.innerHTML = original.innerHTML; container.scrollLeft = clone.offsetLeft var rolling = function() { if(container.scrollLeft == 0) { container.scrollLeft = clone.offsetLeft; } else { container.scrollLeft--; } } var timer = setInterval(rolling, speed) //设置定时器 container.onmouseover = function() { clearInterval(timer) } //鼠标移到marquee上时,清除定时器,停止滚动 container.onmouseout = function() { timer = setInterval(rolling, speed) } //鼠标移开时重设定时器 } window.onload = function() { Marquee("marquee"); } </script> <h1>javascript无缝滚动(向右滚动)</h1> <div id="marquee"> <dl> <dt> <a href="###"><img src="img/o_s017.jpg" alt="javascript无缝滚动"/></a> <a href="###"><img src="img/o_s018.jpg" alt="javascript无缝滚动"/></a> <a href="###"><img src="img/o_s019.jpg" alt="javascript无缝滚动"/></a> <a href="###"><img src="img/o_s020.jpg" alt="javascript无缝滚动"/></a> <a href="###"><img src="img/o_s021.jpg" alt="javascript无缝滚动"/></a> <a href="###"><img src="img/o_s022.jpg" alt="javascript无缝滚动"/></a> <a href="###"><img src="img/o_s023.jpg" alt="javascript无缝滚动"/></a> </dt> <dd></dd> </dl> </div>

效果图如下:

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

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类