纯js轮播图
<div id="wrapper">
<div id="container">
<img src="http://images.cnblogs.com/cnblogs_com/rain-null/1027470/o_001.jpg"alt=""/>
<img src="http://images.cnblogs.com/cnblogs_com/rain-null/1027470/o_003.jpg" alt=""/>
<img src="http://images.cnblogs.com/cnblogs_com/rain-null/1027470/o_04.jpg" alt=""/>
<img src="http://images.cnblogs.com/cnblogs_com/rain-null/1027470/o_005.jpg" alt=""/>
</div>
<span id="p" class="pre">< </span>
<span id="n" class="next">> </span>
<div class="shows">
<span item="1" class="show"></span>
<span item="2"></span>
<span item="3"></span>
<span item="4"></span>
<div>
</div> <style> *{margin:0;padding:0}
#wrapper{width:400px;height:400px;margin:100px auto;overflow:hidden;position:relative}
div#container{width:1600px;height:400px;position:absolute}
div#container img{width:400px;height:400px;float:left;}
#wrapper>span{cursor:pointer;position:absolute;font-size:40px;z-index:5;top:40%;color:#bdbdbd;font-size:3.6em;}
#wrapper span.pre{left:20px;}
#wrapper span.next{right:20px;}
div.shows{position:absolute;bottom:10px;right:20px;z-index:5;width:200px;height:50px;}
div.shows span{width:15px;border:1px solid grey;margin-left:15px;float:left;display:inlin-block;height:15px;border-radius:15px}
.show{background:red} </style> <script> window.onload=function(){
var wrapper=document.getElementById("wrapper");
var dis=document.getElementById("container");
var pre=document.getElementById("p");
var next=document.getElementById("n");
var list=document.getElementsByClassName("shows")[0];
var lists=list.getElementsByTagName("span");
var index=1; function animate(offset){
if(!(dis.style.left)){dis.style.left=dis.style.top=0}
var x=parseInt(dis.style.left)+offset;
dis.style.left=x+"px";
if(x<-1200){dis.style.left=0;}
if(x>0){dis.style.left=-1200+"px"};
} function play(){
timer=setInterval(function(){next.onclick();},1500);}
play();
wrapper.onmouseover=function(){clearInterval(timer)}
wrapper.onmouseout=function(){play()} pre.onclick=function(){
index-=1;
if(index<1){index=4;}
showitem();
animate(400);
} next.onclick=function(){
index+=1;
if(index>4){index=1;}
showitem();
animate(-400);
} function showitem(){
for(var i=0,len=lists.length;i<len;i++)
{
if(lists[i].className=="show"){lists[i].className=""}
}
lists[index-1].className="show";
} for(var i=0,len=lists.length;i<len;i++){
lists[i].onclick=function(){
var currentindex=parseInt(this.getAttribute("item"));
var offset=400*(index-currentindex);
animate(offset);
index=currentindex;
showitem();}
}
}
</script>
效果图:

纯js轮播图的更多相关文章
- 纯js轮播图练习-1
偶尔练习,看视频自己学着做个简单的纯JS轮播. 简单的纯js轮播图练习-1. 样子就是上面图片那样,先不管好不好看,主要是学会运用和理解轮播的原理 掌握核心的理论知识和技术的操作,其他的都可以在这个基 ...
- 纯js轮播图练习-2,js+css旋转木马层叠轮播
基于css3的新属性,加上js的操作,让现在js轮播图花样越来越多. 而现在出现的旋转木马层叠轮播的轮播图样式,却是得到了很多人都喜爱和投入使用. 尤其是在各大软件中,频繁的出现在大家的眼里,在web ...
- 纯js轮播图练习-3,类似于淘宝海报带小圆点轮播图
基于js和css,跟着网上的视频教程,结合自己想要的效果,做出了一个类似于淘宝海报的效果. 如图:淘宝首页 自己做的: 代码: <!DOCTYPE html> <html> & ...
- 纯css3 轮播图 利用keyframes
效果: 关键点:利用keyframes 原理:infinite 注意点:在处理关键帧动画的时候,注意处理好 总共花费的 animation-duration:time 与每帧延延迟的时间的交错:要让 ...
- 纯CSS3轮播图
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- JavaScript的案例(数据校验,js轮播图,页面定时弹窗)
1.数据校验 步骤 1.确定事件(onsubmit)并绑定一个函数 2.书写这个函数,获取数据,并绑定id 3. ...
- javascript原生js轮播图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JS轮播图(网易云轮播图)
JS 轮播图 写在前面 最聪明的人是最不愿浪费时间的人.--但丁 实现功能 图片自动切换 鼠标移入停止自动播放,显示按钮 点击按钮,实现前后翻 鼠标移入小圆圈,可以跳转到对应图片 点击左右两侧图片部分 ...
- css 纯css轮播图 示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
随机推荐
- 使用bootstrap-table等自动使用ajax地址载入数据的插件的数据设计建议
提出问题: bootstrap-table 可以根据ajax地址load的json数据.这个json数据一般就是数据库中查询的结果,而数据库中存放的数据一般不是用户友好的,比如数据表示一般使用简洁id ...
- RN_ 错误整理
1. this.setState is not a function 或者 this.setState is undefined 在 constructor 中加入 this.select = t ...
- [转] java获取hostIp和hostName
[From] https://www.cnblogs.com/huluyisheng/p/6867370.html InetAddress的构造函数不是公开的(public),所以需要通过它提供的静态 ...
- AHB协议
AHB2 支持多个Bus Master,例如有三个Master,有四个slave,但是同时只有一个Mater可以拿到Bus的访问权.所以,总线的使用权就需要Master去申请,也就需要一个仲裁器(Ar ...
- 爬虫--requeste
1.requeste模块,是我们Python对我们爬虫有好的一面,,其主要作用是用来模拟浏览器发起请求.功能强大,用法简洁高效.在爬虫领域中占据着半壁江山的地位.没有的话直接pip3 install ...
- [转]常用 GDB 命令中文速览
目录 break -- 在指定的行或函数处设置断点,缩写为 b info breakpoints -- 打印未删除的所有断点,观察点和捕获点的列表,缩写为 i b disable -- 禁用断点,缩写 ...
- 使用Hive Rest API 连接HDInsight
以下连接是微软最新的关于HDInsight中Hive命令的RestAPI示例地址.. 使用 HDInsight .NET SDK 运行 Hive 查询 请使用接口有异常的同学检查是否使用的是下面地址中 ...
- (转)最新版 nginx内置变量 大全
原文:http://www.cnphp.info/nginx-embedded-variables-lasted-version.html 在配置基于nginx服务器的网站时,必然会用到 nginx内 ...
- git提交过程中遇到的 index.lock 问题导致无法提交的解决方法
在提交代码的过程中,可能会遇到下面的问题: fatal: Unable to create 'C:/programLists/zzw-q1/.git/index.lock': File exists. ...
- android volley 发送 POST 请求
Map<String, String> params = new HashMap<String, String>(); params.put("fromUser&qu ...