自己练习的无缝滚动原生JS
2012-11-03 16:17
330 查看
看了妙趣的课堂自己练习的,因为牵涉到远程就没利用图片 <!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" /> <title>无标题文档</title> <style> div,ul,li,a{ margin:0; padding:0} ul,li{list-style:none} .roll{width:560px; margin:50px auto;overflow:hidden; position:relative} .prev,.next{ width:80px;height:80px;background:#ccc; color:#fff} .prev{position:absolute;left:0;top:20px;} .next{position:absolute;right:0;top:20px;} .scroll{position:relative;left:100px;width:360px;height:100px;overflow:hidden} .scroll ul{position:absolute;left:0} .scroll li{width:100px;height:100px;margin:0 10px; float:left;text-align:center} </style> <script> window.onload = function(){ var odiv = document.getElementById('roll'); var oul = odiv.getElementsByTagName('ul')[0]; var oli = odiv.getElementsByTagName('li'); var obtn = odiv.getElementsByTagName('a') var speed = 30; var timer; oul.innerHTML += oul.innerHTML; oul.style.width = (oli[0].offsetWidth+oli[0].offsetLeft*2)*oli.length+'px'; timer = setInterval(function(){ oul.style.left = oul.offsetLeft+speed+'px'; if(oul.offsetLeft < -oul.offsetWidth/2){ oul.style.left = '0px' }else if(oul.offsetLeft > 0){ oul.style.left = -oul.offsetWidth/2+'px' } },300) obtn[0].onmouseover = function(){ speed =-30 } obtn[1].onmouseover = function(){ speed =30 } oul.onmouseover= function(){ clearInterval(timer) } oul.onmouseout= function(){ timer = setInterval(function(){ oul.style.left = oul.offsetLeft+speed+'px'; if(oul.offsetLeft < -oul.offsetWidth/2){ oul.style.left = '0px' }else if(oul.offsetLeft > 0){ oul.style.left = -oul.offsetWidth/2+'px' } },300) } } </script> </head> <body> <div class="roll" id ="roll"> <a href="###" class="prev">左侧按钮</a> <a href="###" class="next">右侧按钮</a> <div class="scroll clearfix"> <ul> <li style="background:#f7f">第一个</li> <li style="background:#0fc">第二个</li> <li style="background:red">第三个</li> <li style="background:green">第四个</li> </ul> </div> </div> </body> </html>
通过 为知笔记 发布
相关文章推荐
- js原生上下轮播无缝滚动头条循环MUI
- (原生JS) 图片无缝滚动、图片转化、轮播图、折叠效果
- 【原生js】详解轮播图之无缝滚动
- js基础练习---图片无缝左右滚动效果(主要以复制删除为主)
- js原生轮播图 —— 无缝滚动的原理
- 原生js实现无缝滚动
- 10行原生JS实现文字无缝滚动
- 原生js移动端列表无缝间歇向上滚动
- 10行原生JS实现文字无缝滚动(超简单)
- 原生JS练习计算器和banner条滚动效果
- 原生JS实现图片无缝滚动方法(附带封装的运动框架)
- 原生Js实现图片无缝滚动
- 原生JS无缝滚动
- 原生Js无缝滚动效果的简单实现
- 无缝滚动效果原生js
- 无缝滚动原生js
- JS 无缝滚动 走马灯
- js图片无缝滚动代码
- js实现无缝滚动
- js实现标准无缝滚动