js原生的轮播图
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title></title> | |
| <style> | |
| *{ | |
| margin: 0; | |
| padding: 0; | |
| text-decoration: none; | |
| } | |
| #container{ | |
| width: 600px; | |
| height: 400px; | |
| border: 3px solid gold; | |
| position: relative; | |
| margin: 300px auto; | |
| overflow: hidden; | |
| z-index: 2; | |
| /*transition: all 0.5s ease;*/ | |
| } | |
| #list{ | |
| width: 3600px; | |
| height: 400px; | |
| position: absolute; | |
| z-index: 1; | |
| left: -600px; | |
| } | |
| #list img{ | |
| width: 600px; | |
| height: 400px; | |
| float: left; | |
| } | |
| span{ | |
| position: absolute; | |
| display: block; | |
| width: 10px; | |
| height: 10px; | |
| border-radius: 50%; | |
| z-index: 2; | |
| background: gainsboro; | |
| bottom: 10px; | |
| } | |
| p{ | |
| z-index: 2; | |
| width: 50px; | |
| line-height: 50px; | |
| background: rgba(0,0,0,0.3); | |
| color: white; | |
| position: absolute; | |
| font-size: 40px; | |
| text-align: center; | |
| } | |
| .p1{ | |
| top: 175px; | |
| left: 0; | |
| } | |
| .p2{ | |
| top: 175px; | |
| right: 0px; | |
| } | |
| #container:hover .p1,#container:hover .p2{ | |
| background: rgba(0,0,0,0.7); | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="container"> | |
| <div id="list"> | |
| <img src="img/4.jpg" alt="" /> | |
| <img src="img/1.jpg" alt="" /> | |
| <img src="img/2.jpg" alt="" /> | |
| <img src="img/3.jpg" alt="" /> | |
| <img src="img/4.jpg" alt="" /> | |
| <img src="img/1.jpg" alt="" /> | |
| </div> | |
| <p class="p1" onclick="lfClick(10)"><</p> | |
| <p class="p2" onclick="lfClick(-10)">></p> | |
| <span onclick="oClick(-600,0)"></span> | |
| <span onclick="oClick(-1200,1)"></span> | |
| <span onclick="oClick(-1800,2)"></span> | |
| <span onclick="oClick(-2400,3)"></span> | |
| </div> | |
| </body> | |
| <script type="text/javascript"> | |
| var list = document.getElementById('list'); | |
| var ps = document.querySelectorAll('p'); | |
| var timer = null ; | |
| var spans = document.querySelectorAll('span'); | |
| var timeOut = null; | |
| for(var i = 0 ;i<spans.length; i++){ | |
| spans[i].style.left = 250 + i*20 + 'px'; | |
| } | |
| timer=setInterval(doMove,20); | |
| function doMove(){ | |
| var speed = parseInt(getStyle()) - 10; | |
| list.style.left = speed +'px'; | |
| if(speed %600 ==0){ | |
| clearInterval(timer); | |
| timeOut = setTimeout(function(){ | |
| timer=setInterval(doMove,20); | |
| },1000); | |
| } | |
| btnColor(speed); | |
| } | |
| //前后事件 | |
| var setInter =null; | |
| // ps[0].onclick = lfClick(10); | |
| function lfClick(dir) { | |
| clearInterval(timer); | |
| clearInterval(setInter); | |
| if(parseInt(getStyle()) < -600 && parseInt(getStyle())>-1200){ | |
| list.style.left = -600 +'px'; | |
| } | |
| if(parseInt(getStyle()) < -1200 && parseInt(getStyle())>-1800){ | |
| list.style.left = -1200 +'px'; | |
| } | |
| if(parseInt(getStyle()) < -1800 && parseInt(getStyle())>-2400){ | |
| list.style.left = -1800 +'px'; | |
| } | |
| if(parseInt(getStyle()) < -2400 && parseInt(getStyle())>-3000){ | |
| list.style.left = -2400 +'px'; | |
| } | |
| setInter = setInterval(function(){ | |
| clearInterval(timer); | |
| clearTimeout(timeOut); | |
| var speed = parseInt(getStyle()) + dir ; | |
| list.style.left = speed + 'px'; | |
| btnColor(speed); | |
| if(speed %600 == 0){ | |
| clearInterval(setInter); | |
| timeOut = setTimeout(function(){ | |
| timer=setInterval(doMove,20); | |
| },1000); | |
| if(speed == 0){ | |
| list.style.left = '-2400px'; | |
| } | |
| if(speed == -3000){ | |
| list.style.left = '-600px'; | |
| } | |
| } | |
| },10) | |
| } | |
| function getStyle(){ | |
| return list.currentStyle? list.currentStyle.left:getComputedStyle(list).left; | |
| } | |
| function oClick(dir,index){ | |
| clearInterval(timer); | |
| clearTimeout(timeOut) | |
| list.style.left = dir + 'px'; | |
| for(var i = 0 ;i<spans.length; i++){ | |
| spans[i].style.background='gainsboro'; | |
| } | |
| spans[index].style.background = 'red'; | |
| timeOut = setTimeout(function(){ | |
| timer=setInterval(doMove,20); | |
| },1000); | |
| } | |
| function btnColor(speed){ | |
| if(speed == -600 ){ | |
| spans[0].style.background = 'red'; | |
| spans[3].style.background = 'gainsboro'; | |
| spans[1].style.background = 'gainsboro'; | |
| } | |
| if(speed == -1200 ){ | |
| spans[1].style.background = 'red'; | |
| spans[0].style.background = 'gainsboro'; | |
| spans[2].style.background = 'gainsboro'; | |
| } | |
| if(speed == -1800){ | |
| spans[2].style.background = 'red'; | |
| spans[1].style.background = 'gainsboro'; | |
| spans[3].style.background = 'gainsboro'; | |
| } | |
| if(speed == -2400 ||speed ==0){ | |
| spans[3].style.background = 'red'; | |
| spans[2].style.background = 'gainsboro'; | |
| spans[0].style.background = 'gainsboro'; | |
| } | |
| if(speed == -3000){ | |
| list.style.left = -600 +'px'; | |
| spans[0].style.background = 'red'; | |
| spans[3].style.background = 'gainsboro'; | |
| } | |
| } | |
| </script> | |
| </html> |
js原生的轮播图的更多相关文章
- js原生实现轮播图效果(面向对象编程)
面向对象编程js原生实现轮播图效果 1.先看效果图 2.需要实现的功能: 自动轮播 点击左右箭头按钮无缝轮播 点击数字按钮切换图片 分析:如何实现无缝轮播? 在一个固定大小的相框里有一个ul标签,其长 ...
- JS+css3焦点轮播图PC端
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jQuery与原生js实现banner轮播图
jQuery与原生js实现banner轮播图: (jq需自己加载)(图片需自己加载) <!DOCTYPE html> <html> <head> <meta ...
- 原生JS实现简易轮播图
原生JS实现简易轮播图(渐变?) 最近做网页总是会用到轮播图,我就把之前写的轮播图单独拿出来吧,如果有...如果真的有人也需要也可以复制去用用啊..哈~.. window.onload = funct ...
- 原生 js 左右切换轮播图
使用方法: 可能很多人对轮播图感兴趣,下面奉上本人的 原生 js 轮播代码复制 js 到页面的最底部,样式在 css 里改,js 基本不用动,有什么不懂的可以 加本人 QQ172360937 咨询 或 ...
- 自己用原生JS写的轮播图,支持移动端触屏滑动,面向对象思路。分页器圆点支持click和mouseover。
自己用原生javascript写的轮播图,面向对象思路,支持移动端手指触屏滑动.分页器圆点可以选择click点击或mouseover鼠标移入时触发.图片滚动用的setInterval,感觉setInt ...
- 原生JS实现旋转木马轮播图特效
大概是这个样子: 首先来简单布局一下(emm...随便弄一下吧,反正主要是用js来整的) <!DOCTYPE html> <html lang="en"> ...
- photoSlider-html5原生js移动开发轮播图-相册滑动插件
简单的移动端图片滑动切换浏览插件 分别引用css文件和js文件 如: <link rel="stylesheet" type="text/css" hre ...
- 自己用原生JS写的轮播图,支持移动端触摸滑动,分页器圆点可以支持mouseover鼠标移入和click点击,高手看了勿喷哈
自己用原生JavaScript写的轮播图,分页器圆点按钮可支持click点击,也可支持mouseover鼠标悬浮触发,同时支持移动端触摸滑动,有兴趣的友友可以试试哈,菜鸟一枚,高手看了勿喷,请多多指正 ...
随机推荐
- configparser配置文件模块
1.configparser的作用 mysql等很多文件的配置如下: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLeve ...
- USTC 1119 graph 图的同构
USTC 1119 图的同构的严格定义可以参考离散数学:The simple graphs G1=(V1,E1) and G2=(V2,E2)are isomorphic if there exist ...
- SQL语句使用时间和日期的函数
getdate():获取系统当前时间dateadd(datepart,number,date):计算在一个时间的基础上增加一个时间后的新时间值,比如:dateadd(yy,30,getdate())d ...
- Hibernate双向关联的增删改操作的属性
双向关联关系下的增删改操作的属性 1.cascade属性: eg:<set name = "emps" cascade="s ...
- Smarty模板的基础
对前后端进行分离 如果要用的话,要从网上把smarty文件下载下来,才能用 smarty的核心是一个类 建一个php文件,写一个类文件 <?php class smarty { public $ ...
- 使用curl操作InfluxDB
这里列举几个简单的示例代码,更多信息请参考InfluxDB官方文档: https://docs.influxdata.com/influxdb/v1.1/ 环境: CentOS6.5_x64Influ ...
- Struts文件下载
/* 文件下载的先决条件 * 1. 在xml配置文件中必须配置一个type="stream"的result, result中不需要填写任何内容 * 2. 在Action中编写一个接 ...
- Isomorphic Strings leetcode
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Ubuntu 不支持 rpm
不是第一次犯这个错误了. 记一下. 每次安装jdk 的时候,习惯性下载rpm包. 然后的,然后在 ubuntu上rpm 安装的时候就跪了.. ubuntu需要使用Alien 把rpm 转成 deb再安 ...
- PHP后台程序员工作到如今的一点心得
一个项目的建立,一开始一定要有需求文档,没有需求文档的项目注定会改来改去.还被骂的很惨.要时刻牢记一句话:口说无凭,有文档为证. 第一:开发语言的选择,PHP,当然还有JAVA,.NET你做的项目当然 ...