<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">&lt </span>
<span id="n" class="next">&gt </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轮播图的更多相关文章

  1. 纯js轮播图练习-1

    偶尔练习,看视频自己学着做个简单的纯JS轮播. 简单的纯js轮播图练习-1. 样子就是上面图片那样,先不管好不好看,主要是学会运用和理解轮播的原理 掌握核心的理论知识和技术的操作,其他的都可以在这个基 ...

  2. 纯js轮播图练习-2,js+css旋转木马层叠轮播

    基于css3的新属性,加上js的操作,让现在js轮播图花样越来越多. 而现在出现的旋转木马层叠轮播的轮播图样式,却是得到了很多人都喜爱和投入使用. 尤其是在各大软件中,频繁的出现在大家的眼里,在web ...

  3. 纯js轮播图练习-3,类似于淘宝海报带小圆点轮播图

    基于js和css,跟着网上的视频教程,结合自己想要的效果,做出了一个类似于淘宝海报的效果. 如图:淘宝首页 自己做的: 代码: <!DOCTYPE html> <html> & ...

  4. 纯css3 轮播图 利用keyframes

    效果: 关键点:利用keyframes 原理:infinite 注意点:在处理关键帧动画的时候,注意处理好 总共花费的 animation-duration:time  与每帧延延迟的时间的交错:要让 ...

  5. 纯CSS3轮播图

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. JavaScript的案例(数据校验,js轮播图,页面定时弹窗)

    1.数据校验            步骤            1.确定事件(onsubmit)并绑定一个函数            2.书写这个函数,获取数据,并绑定id            3. ...

  7. javascript原生js轮播图

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. JS轮播图(网易云轮播图)

    JS 轮播图 写在前面 最聪明的人是最不愿浪费时间的人.--但丁 实现功能 图片自动切换 鼠标移入停止自动播放,显示按钮 点击按钮,实现前后翻 鼠标移入小圆圈,可以跳转到对应图片 点击左右两侧图片部分 ...

  9. css 纯css轮播图 示例

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

随机推荐

  1. 《Fixed Income Portfolio Analytics》阅读笔记——第零部分

    <Fixed Income Portfolio Analytics>第零部分的思维导图. <Fixed Income Portfolio Analytics>阅读笔记--第零部 ...

  2. NVIDIA TX1/TX2 对比

    处理器方面,TX2由TX1的Tegra X1升至Tegra Parker处理器,该处理器由16nm工艺制造,6核心设计,CPU部分由2个丹佛+4个A57核心共同组成. GPU则采用Pascal架构,拥 ...

  3. 蒙版 mask

    一句话理解: "被蒙版"层 只显示的区域为: "蒙版"层中不透明的部分 (即:最终显示的内容是父层的, 区域大小受蒙版不透明部分控制)

  4. PHP单表操作mysqli数据库类的封装

    class DB{ private $options=array( 'database_type' => 'mysql', 'database_name' => 'test', 'serv ...

  5. truffle使用详解

    truffle使用详解 truffle是什么 Truffle测试环境 安装truffle truffle项目结构解析 文件编译 truffle的配置文件 移植 与合约进行交互 1.truffle是什么 ...

  6. spring切面拦截实现

    1.建立业务类(英雄战斗实现类) package com.g2.api; public interface Weapon { int attack(); String getName(); } pac ...

  7. [转] Jenkins pipeline 踩坑集合

    [From] https://testerhome.com/topics/10328 前言 最近由于项目需要,接触到了Jenkins 2.0版本,其中最重要的特性就是提供了对pipeline的支持.简 ...

  8. 【Python】子域名查询脚本

    脚本学习,多写写就会啦,来一发个人编写的超级无敌low的子域名查询脚本 #coding:utf-8 import re import requests import urllib import url ...

  9. js计算日期相差天数

    日期不能直接相加减比较大小,需要转换一下然后计算最后转换成天,当然,你也可以根据同样类似的方法去转换成小时,或者月,年. function DateDiff(sDate1, sDate2) { //s ...

  10. Django Rest Framework(阿奇)

    Django Rest Framework 一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中 ...