纯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 ...
随机推荐
- 使用 WebClient 來存取 GET,POST,PUT,DELETE,PATCH 網路資源
WebClient 基本資訊 提供通用方法使用 WebRequest 類別傳送及接收 URI (支援 http:, https:, ftp:,和 file: ) 的資源 Namespace:Syste ...
- 虚拟立方体调用非共享维度的时候需要指定cubeName,否则Schema无效
但是,即使把非共享维度放上去,会出现一种情况. 一旦放入资产负债的非公共维度进去后,报表的度量值只能出现资产负债的度量值,不能出现损益的度量值了!
- Sklearn,TensorFlow,keras模型保存与读取
一.sklearn模型保存与读取 1.保存 from sklearn.externals import joblib from sklearn import svm X = [[0, 0], [1, ...
- 论文阅读 | RefineDet:Single-Shot Refinement Neural Network for Object Detection
论文链接:https://arxiv.org/abs/1711.06897 代码链接:https://github.com/sfzhang15/RefineDet 摘要 RefineDet是CVPR ...
- 3-----Docker实例-安装MySQL
Docker 安装 MySQL 方法一.docker pull mysql 查找Docker Hub上的mysql镜像 runoob@runoob:/mysql$ docker search mysq ...
- android面试注意点
Java 基础知识 面向对象的基本思想 Object类相关:Object类的几个关键函数.String涉及到的常量池概念,序列化 & 反序列化. 重要关键字:final.static. 内部类 ...
- hey-cli初使用
当前项目负责人打算用hey-cli ,初步接触了hey-cli 是一款比vue-cli使用还要简单的脚手架 1. 先全局安装hey-cli npm install -g hey-cli 2. 初 ...
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- 入门系列之在Ubuntu上使用MySQL设置远程数据库优化站点性能
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由苏子晨 发表于云+社区专栏 介绍 随着您的应用程序或网站的增长,您可能已经超出了当前的服务器设置.如果您在同一台计算机上托管Web服务 ...
- android studio应用获取系统属性权限(SystemProperties)
dependencies { provided files(getLayoutLibPath()) } /** ZhangChao time:2014-12-31,get layoutlib.jar ...