js实现轮播图
2017-08-23 19:26
274 查看
js实现轮播图
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js轮播</title>
<style type="text/css">
body{
overflow-x:hidden;
}
div{margin: 0 auto;}
.lunboImg{position: relative;width: 1200px;border: 1px solid red;height: 500px;}
img{position: relative;}
ul{position: absolute;list-style: none;}
.lunboContro li{float:left;margin-left: 35px}
.lunboContro{position: relative;left: 500px;top:-60px;}
li div{width: 26px;background-color:white;height: 26px;border:1px solid red;border-radius: 15px}
</style>
<script type="text/javascript">
window.onload=function(){
var lis=document.getElementsByTagName("li");
var pic=document.getElementById("pic");
for (var i = 0; i < lis.length; i++) {
/*鼠标经过触发*/
lis[i].onmouseover=function(){
clearInterval(t);
for(i=0;i<lis.length;i++){
if(lis[i]!=this){
lis[i].childNodes[0].style.backgroundColor="white";
}
}
if(this.value==4){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img04.jpg";
}
if(this.value==3){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img03.jpg";
}
if(this.value==2){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img02.jpg";
}
if(this.value==1){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img01.jpg";
}
}
/*鼠标离开触发*/
lis[i].onmouseout=function(){
num=this.value;
t=setInterval(function(){
// alert(num);
pic.src="../img/banner_img0"+num+".jpg";
for(var i=0;i<lis.length;i++){
if(num==lis[i].value){
lis[i].childNodes[0].style.backgroundColor="red";
}else{
lis[i].childNodes[0].style.backgroundColor="white";
}
}
num++;
if(num==5){ num=1; }
}, 2000);
this.childNodes[0].style.backgroundColor="red";
}
/*点击鼠标触发*/
lis[i].onclick=function(){
if(this.value==4){
pic.src="../img/banner_img04.jpg";
}
if(this.value==3){
pic.src="../img/banner_img03.jpg";
}
if(this.value==2){
pic.src="../img/banner_img02.jpg";
}
if(this.value==1){
pic.src="../img/banner_img01.jpg";
}
}
}
/*设置定时器,每2s换图*/
num=1;
var t=setInterval(function(){
// alert(num);
pic.src="../img/banner_img0"+num+".jpg";
for(var i=0;i<lis.length;i++){
if(num==lis[i].value){
lis[i].childNodes[0].style.backgroundColor="red";
}else{
lis[i].childNodes[0].style.backgroundColor="white";
}
}
num++;
if(num==5){ num=1; }
}, 2000);
}
</script>
</head>
<body>
<div style="width: 100%;height: 600px; border: 1px solid blue" >
<div class="lunboImg" >
<img alt="" src="../img/banner_img01.jpg" width="100%" height="100%" id="pic">
</div>
<div class="lunboContro">
<ul type="circle">
<li value="1"><div style="background-color: red"></div></li>
<li value="2"><div></div></li>
<li value="3"><div></div></li>
<li value="4"><div></div></li>
</ul>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js轮播</title>
<style type="text/css">
body{
overflow-x:hidden;
}
div{margin: 0 auto;}
.lunboImg{position: relative;width: 1200px;border: 1px solid red;height: 500px;}
img{position: relative;}
ul{position: absolute;list-style: none;}
.lunboContro li{float:left;margin-left: 35px}
.lunboContro{position: relative;left: 500px;top:-60px;}
li div{width: 26px;background-color:white;height: 26px;border:1px solid red;border-radius: 15px}
</style>
<script type="text/javascript">
window.onload=function(){
var lis=document.getElementsByTagName("li");
var pic=document.getElementById("pic");
for (var i = 0; i < lis.length; i++) {
/*鼠标经过触发*/
lis[i].onmouseover=function(){
clearInterval(t);
for(i=0;i<lis.length;i++){
if(lis[i]!=this){
lis[i].childNodes[0].style.backgroundColor="white";
}
}
if(this.value==4){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img04.jpg";
}
if(this.value==3){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img03.jpg";
}
if(this.value==2){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img02.jpg";
}
if(this.value==1){
this.childNodes[0].style.backgroundColor="red";
pic.src="../img/banner_img01.jpg";
}
}
/*鼠标离开触发*/
lis[i].onmouseout=function(){
num=this.value;
t=setInterval(function(){
// alert(num);
pic.src="../img/banner_img0"+num+".jpg";
for(var i=0;i<lis.length;i++){
if(num==lis[i].value){
lis[i].childNodes[0].style.backgroundColor="red";
}else{
lis[i].childNodes[0].style.backgroundColor="white";
}
}
num++;
if(num==5){ num=1; }
}, 2000);
this.childNodes[0].style.backgroundColor="red";
}
/*点击鼠标触发*/
lis[i].onclick=function(){
if(this.value==4){
pic.src="../img/banner_img04.jpg";
}
if(this.value==3){
pic.src="../img/banner_img03.jpg";
}
if(this.value==2){
pic.src="../img/banner_img02.jpg";
}
if(this.value==1){
pic.src="../img/banner_img01.jpg";
}
}
}
/*设置定时器,每2s换图*/
num=1;
var t=setInterval(function(){
// alert(num);
pic.src="../img/banner_img0"+num+".jpg";
for(var i=0;i<lis.length;i++){
if(num==lis[i].value){
lis[i].childNodes[0].style.backgroundColor="red";
}else{
lis[i].childNodes[0].style.backgroundColor="white";
}
}
num++;
if(num==5){ num=1; }
}, 2000);
}
</script>
</head>
<body>
<div style="width: 100%;height: 600px; border: 1px solid blue" >
<div class="lunboImg" >
<img alt="" src="../img/banner_img01.jpg" width="100%" height="100%" id="pic">
</div>
<div class="lunboContro">
<ul type="circle">
<li value="1"><div style="background-color: red"></div></li>
<li value="2"><div></div></li>
<li value="3"><div></div></li>
<li value="4"><div></div></li>
</ul>
</div>
</div>
</body>
</html>
相关文章推荐
- js实现轮播图(二)
- 原生JS实现"旋转木马"效果的图片轮播插件
- js实现图片轮播效果
- 基于vue.js实现图片轮播效果
- js实现轮播图效果(附源码)--原生js的应用
- 使用html+js+css 实现页面轮播图效果(实例讲解)
- JS 实现产品图片的轮播,支持向左向右滚动
- js实现图片轮播
- js实现图片轮播
- Hammer.js+轮播原理实现简洁的滑屏功能
- jquery.superslider.js实现轮播图懒加载,一级jquery.lazyload.js实现图片的懒加载
- Arcgis for Js实现Spline插值、区域裁剪以及页面的轮播效果
- js实现有过渡渐变效果的图片轮播相册(兼容IE,ff)
- JS实现排行榜文字向上滚动轮播
- js实现图片轮播(由简到复杂)
- 原生js图片轮播效果实现代码
- JS实现文字向上无缝滚动轮播
- jQuery实现图片轮播效果代码(基于jquery.pack.js插件)
- JS轮播图效果实现
- 用原生js实现无缝轮播