百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>JS教程> 基于JavaScript实现带缩略图的轮播效果
分享文章到:

基于JavaScript实现带缩略图的轮播效果

发布时间:01/15 来源: 浏览: 关键词:
这篇文章介绍了基于JavaScript实现带缩略图的轮播效果的教程,有兴趣的同学可以参考一下本文

先瞄一眼js轮播效果图

代码:

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>

<style>

*{padding:0;margin:0;}

#content {width:400px;height:500px;margin:10px auto;position:relative;border:1px solid #000;color:red;font-size:20px;}

#title, #bottom{position:absolute;width:400px;height:30px;line-height:30px;text-align:center;font-size:20px;background:#f1f1f1;}

#bottom{bottom:0;cursor:pointer;}

#bottom span{display:inline-block;width:15px;height:15px;border-radius:15px;background:#000;text-align:center;line-height:15px;position:relative;}

#bottom span.active{background: #FFFF33;}

#bottom span div {position:absolute;width:110px;height:110px;top:-125px;left:-46px;display:none;}

#bottom span div:after{content:'';position:absolute;left:49px;bottom:-12px;border-top:7px solid #fff;border-right:5px solid transparent;border-bottom:5px solid transparent;border-left:5px solid transparent;}

#bottom span img {width:100px;height:100px;border:5px solid #fff;}

#left, #right{position:absolute;width:60px;height:60px;border-radius:60px;line-height:60px;font-size:60px;background:#FFFF66;font-weight:bold;text-align:center;top:50%;margin-top:-25px;color:#fff;cursor:pointer;filter(opacity:70);opacity:0.7;}

#left:hover,#right:hover{filter(opacity:100);opacity:1;}

#left{left:0px;}

#right{right:0px;}

#img{width:400px;height:500px;}

</style>

<script>

window.onload = function () {

 var bottom = $('bottom'),title = $('title'),

  img = $('img'),left = $('left'),right = $('right');

 var aSpan = bottom.getElementsByTagName('span');

 var aDiv = bottom.getElementsByTagName('div');

 var arr = ['图片一','图片二','图片三', '图片四'];

 var num = 0;

 // 初始化

 picTab();

 

 // 点击下一张

 right.onclick = function () {

  if (num === aDiv.length - 1) num = -1;

  num++;

  picTab();

 }

 

 // 点击上一张

 left.onclick = function () {

  if (num === 0) num = aDiv.length;

  num--;

  picTab();

 }

 

 function picTab() {

  title.innerHTML = arr[num];

  img.src = 'img/' + (num + 1) + '.png';

  for ( var i = 0; i <aSpan.length; i++ ) {

   aSpan[i].className='';

  }

  aSpan[num].className='active';

 }

 // 鼠标移入移出显示缩略图

 for ( vari=0; i < aSpan.length; i++ ) {

  aSpan[i].index= i;

  aSpan[i].onmouseover=function() {

   aDiv[this.index].style.display='block';

  }

  aSpan[i].onmouseout=function() {

   aDiv[this.index].style.display='none';

  }

  aSpan[i].onclick=function() {

   num=this.index;

   picTab();

  }

 }

 function $(id) { return document.getElementById(id);}

}

</script>

</head>

<body>

<divid="content">

 <divid="title">带缩略图的轮播</div>

 <divid="left"><</div>

 <divid="right">></div>

 <divid="bottom">

  <span><div><imgsrc="img/1.png"/></div></span>

  <span><div><imgsrc="img/2.png"/></div></span>

  <span><div><imgsrc="img/3.png"/></div></span>

  <span><div><imgsrc="img/4.png"/></div></span>

 </div>

 <imgsrc=""id="img"/>

</div>

</body>

</html>

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有12人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板