jquery實(shí)現(xiàn)輪播圖效果
效果如下:
代碼如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>slider</title> <style type="text/css"> *{ margin: 0; padding: 0; } #slideshow{ position: relative; width: 512px; height: 384px; margin: 0 auto; overflow: hidden; } #slideshow>ul,#slideshow>ul>li,#slideshow-nav{ position: absolute; } #slideshow>ul>li{ list-style: none; } #slideshow-nav{ bottom: 20px; width: 100%; text-align: center; } #slideshow-nav>span{ display: inline-block; width: 15px; height: 15px; margin: 0 7px; font-size: 0; background-color: rgba(255,255,255,.3); border-radius: 50%; user-select: none; -webkit-user-select: none; transition: all .5s; -webkit-transition: all .5s; cursor: pointer; } #slideshow-nav>span.active{ background-color: #fff; } </style> </head> <body> <div id="slideshow"> <ul> <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201611/26/231154e8ab2zanwd59a2w2.jpg" alt="gakki is mine"></li> <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201611/26/231236ugj2glgcl6g66gg4.jpg" alt="gakki is mine"></li> <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201611/26/231236c26bx5bbfp6kazzm.jpg" alt="gakki is mine"></li> <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201611/26/231236oqd8i8q158ojr0i7.jpg" alt="gakki is mine"></li> <li><img src="http://cdn.attach.qdfuns.com/notes/pics/201611/26/231236o1iud19lkz11wqja.jpg" alt="gakki is mine"></li> </ul> <div id="slideshow-nav"></div> </div> <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ var timer = null, curindex = 0, duration = 2000, speed = 500; var $imgWrap = $('#slideshow>ul'); var totalIndex = $imgWrap.find('li').length; var width = $('#slideshow').width(); //insert navigate span, let img in order $('#slideshow').find('ul>li').each(function(index){ $(this).css('left', width*index + 'px'); $('#slideshow-nav').append('<span>' + (index+1) + '</span>'); }) // $('#slideshow-nav>span').eq(0).addClass('active'); //auto slide var move = function(){ curindex += 1; if (curindex===totalIndex) { curindex = 0; } // current span add classname "active" $('#slideshow-nav>span').each(function(index) { $(this).removeClass('active') }).eq(curindex).addClass('active'); //auto slide $imgWrap.animate({ 'left': width*curindex*(-1)+'px', }, speed) //一開(kāi)始沒(méi)加"timer = ",這個(gè)bug耽誤了不少時(shí)間 timer = setTimeout(move,duration+speed); }; //init timer = setTimeout(move,duration); //click event $('#slideshow-nav>span').on('click', function(event) { event.preventDefault(); /* Act on the event */ clearTimeout(timer); $imgWrap.stop(true, true); curindex = $(this).index() - 1; move(); }); }) </script> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
- jquery實(shí)現(xiàn)左右輪播圖效果
- JQuery和html+css實(shí)現(xiàn)帶小圓點(diǎn)和左右按鈕的輪播圖實(shí)例
- jquery版輪播圖效果和extend擴(kuò)展
- jQuery制作全屏寬度固定高度輪播圖(實(shí)例講解)
- jquery實(shí)現(xiàn)左右滑動(dòng)式輪播圖
- jQuery實(shí)現(xiàn)一個(gè)簡(jiǎn)單的輪播圖
- jQuery按需加載輪播圖(web前端性能優(yōu)化)
- 用jQuery實(shí)現(xiàn)優(yōu)酷首頁(yè)輪播圖
- jQuery無(wú)縫輪播圖代碼
- jquery 實(shí)現(xiàn)輪播圖詳解及實(shí)例代碼
- 原生Javascript和jQuery做輪播圖簡(jiǎn)單例子
- jQuery實(shí)現(xiàn)簡(jiǎn)潔的輪播圖效果實(shí)例
- jquery寫(xiě)出PC端輪播圖實(shí)例
相關(guān)文章
jquery easyui DataGrid簡(jiǎn)單示例
本篇文章主要介紹了jquery easyui DataGrid簡(jiǎn)單示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01jquery如何根據(jù)值設(shè)置默認(rèn)的選中項(xiàng)
這篇文章主要介紹了jquery如何根據(jù)值設(shè)置默認(rèn)的選中項(xiàng),需要的朋友可以參考下2014-03-03JQuery省市聯(lián)動(dòng)效果實(shí)現(xiàn)過(guò)程詳解
這篇文章主要介紹了JQuery省市聯(lián)動(dòng)效果實(shí)現(xiàn)過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05JQuery 表單中textarea字?jǐn)?shù)限制實(shí)現(xiàn)代碼
textarea中的字?jǐn)?shù)的限制是在1000個(gè)之內(nèi),下面是具體的實(shí)現(xiàn)代碼,基本上會(huì)點(diǎn)jquery的能看懂,不懂的可以學(xué)習(xí)下jquery,當(dāng)期比較流行了,要不就落伍了。2009-12-12jQuery+PHP+MySQL二級(jí)聯(lián)動(dòng)下拉菜單實(shí)例講解
這篇文章主要介紹了一款jQuery+PHP+MySQL三者結(jié)合實(shí)現(xiàn)的二級(jí)聯(lián)動(dòng)下拉菜單,需要的朋友可以參考下2015-10-10jQuery 常見(jiàn)開(kāi)發(fā)使用技巧總結(jié)
下面這些知識(shí)都是開(kāi)發(fā)過(guò)程中,經(jīng)常遇到的。所以整理了下,需要的朋友可以參考下。2009-12-12基于jquery編寫(xiě)的橫向自適應(yīng)幻燈片切換特效的實(shí)例代碼
全屏自適應(yīng)jquery焦點(diǎn)圖切換特效,在IE6這個(gè)瀏覽器兼容性問(wèn)題上得到了和諧,兼容IE6,適用瀏覽器:IE6、IE7、IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.相關(guān)代碼2013-08-08