基于JavaScript實(shí)現(xiàn)帶縮略圖的輪播效果
先瞄一眼js輪播效果圖
代碼:
<html> <head> <meta http-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(); // 點(diǎn)擊下一張 right.onclick = function () { if (num === aDiv.length - 1) num = -1; num++; picTab(); } // 點(diǎn)擊上一張 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'; } // 鼠標(biāo)移入移出顯示縮略圖 for ( var i = 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> <div id="content"> <div id="title">帶縮略圖的輪播</div> <div id="left"><</div> <div id="right">></div> <div id="bottom"> <span><div><img src="img/1.png"/></div></span> <span><div><img src="img/2.png"/></div></span> <span><div><img src="img/3.png"/></div></span> <span><div><img src="img/4.png"/></div></span> </div> <img src="" id="img"/> </div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript中簡(jiǎn)單的進(jìn)制轉(zhuǎn)換代碼實(shí)例
這篇文章介紹了javascript中簡(jiǎn)單的進(jìn)制轉(zhuǎn)換代碼實(shí)例,有需要的朋友可以參考一下2013-10-10超詳細(xì)JavaScript深淺拷貝的實(shí)現(xiàn)教程
淺拷貝是指,一個(gè)新的對(duì)象對(duì)原始對(duì)象的屬性值進(jìn)行精確地拷貝;深拷貝是指,對(duì)于簡(jiǎn)單數(shù)據(jù)類型直接拷貝他的值,對(duì)于引用數(shù)據(jù)類型,在堆內(nèi)存中開(kāi)辟一塊內(nèi)存用于存放復(fù)制的對(duì)象,并把原有的對(duì)象類型數(shù)據(jù)拷貝過(guò)來(lái)。本文將實(shí)現(xiàn)JavaScript深淺拷貝,需要的可以參考一下2022-09-09JS實(shí)現(xiàn)的數(shù)組去除重復(fù)數(shù)據(jù)算法小結(jié)
這篇文章主要介紹了JS實(shí)現(xiàn)的數(shù)組去除重復(fù)數(shù)據(jù)算法,總結(jié)分析了4種比較常見(jiàn)的數(shù)組去重復(fù)算法及相關(guān)使用技巧,需要的朋友可以參考下2017-11-11微信小程序 函數(shù)防抖 解決重復(fù)點(diǎn)擊消耗性能問(wèn)題實(shí)現(xiàn)代碼
這篇文章主要介紹了微信小程序使用函數(shù)防抖解決重復(fù)點(diǎn)擊消耗性能問(wèn)題實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09JS三級(jí)聯(lián)動(dòng)代碼格式實(shí)例詳解
這篇文章主要介紹了JS三級(jí)聯(lián)動(dòng)代碼格式實(shí)例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12uni-app入門頁(yè)面布局之window和tabbar詳解
每個(gè)頁(yè)面按照結(jié)構(gòu)可以分成三部分:window?page?tabbar.其中window和tabbar一般比較固定,page是平常業(yè)務(wù)開(kāi)展的主要載體,根據(jù)業(yè)務(wù)需求進(jìn)行頁(yè)面配置。下面主要講一下window和tabbar,感興趣的朋友跟隨小編一起看看吧2022-11-11javascript封裝簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了javascript封裝簡(jiǎn)單實(shí)現(xiàn)方法,涉及javascript中方法與屬性的相關(guān)設(shè)置與使用技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08