jquery實(shí)現(xiàn)的簡(jiǎn)單輪播圖功能【適合新手】
本文實(shí)例講述了jquery實(shí)現(xiàn)的輪播圖功能。分享給大家供大家參考,具體如下:
前面介紹了原生js實(shí)現(xiàn)的輪播圖,今天就試著用jquery做了個(gè)輪播圖,方法都一樣,但jquery實(shí)現(xiàn)卻比js方便了許多
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>www.dbjr.com.cn jQuery輪播圖</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <style> *{ margin: 0px; padding: 0px; list-style: none; } #flash{ width: 400px; height: 200px; position: relative; margin: 0 auto; border:1px solid black; overflow: hidden; } #falsh img{ width: 100%; height: 100%; position: absolute; left: 0; top: 0; } #flash ul{ position: absolute; left: 25%; bottom: 5%; width: 200px; height: 30px; border-radius: 20px; background-color: rgba(0,0,0,0.5); } #flash ul li{ float: left; width: 15px; height: 15px; border-radius: 50%; background-color: #fff; margin-left: 20px; margin-top: 7px; } #flash ul .li_first{ background-color: #f40; } #flash .button{ width: 50px; height: 50px; border-radius: 50%; background-color: rgba(0,0,0,0.3); cursor: pointer; } #flash .right{ position: absolute; right: 10px; top: 80px; } #flash .left{ position: absolute; left: 10px; top: 80px; } #flash .button span{ font-size: xx-large; font-weight: 700; line-height: 50px; margin-left: 15px; color: rgba(255,255,255,0.5); } </style> </head> <body> <div id="flash"> <img src="http://demo.jb51.net/js/2018/html5-css3-3d-img-flash-codes/images/Guardians-of-the-Galaxy-Poster-High-Res.jpg" alt="" style="display: block"> <img src="http://demo.jb51.net/js/2018/html5-css3-3d-img-flash-codes/images/Blade-Runner-poster-art-Harrison-Ford.jpg" alt=""> <img src="http://demo.jb51.net/js/2018/html5-css3-3d-img-flash-codes/images/2017_alien_covenant_4k-5120x2880-1920x1080.jpg" alt=""> <img src="http://demo.jb51.net/js/2018/html5-css3-3d-img-flash-codes/images/robocop-1987-wallpaper-2.jpg" alt=""> <img src="http://demo.jb51.net/js/2018/html5-css3-3d-img-flash-codes/images/sJALsDXak4EehSg2F2y92rt5hPe.jpg" alt=""> <ul> <li class="li_first"></li> <li></li> <li></li> <li></li> <li></li> </ul> <div class="button right"><span>></span></div> <div class="button left"><span><</span></div> </div> <script> var count = 0 ; //定義全局變量count來(lái)表示當(dāng)前圖片 function run(){ count++; count = count ==5?0:count; $('#flash img').eq(count).fadeIn(300).siblings('img').fadeOut(300); //利用eq來(lái)遍歷img,并將count位圖片顯示,其他兄弟元素隱藏,fadeIN位淡入顯示,fadeOut為淡出 $('#flash ul li').eq(count).css('background','#f40').siblings('li').css('background','#fff'); //同樣利用遍歷改變圓點(diǎn)的背景色 } function reverserun(){ count--; count = count == -1?4:count; $('#flash img').eq(count).fadeIn(300).siblings('img').fadeOut(300); $('#flash ul li').eq(count).css('background','#f40').siblings('li').css('background','#fff'); } var timer = setInterval(run,1000); //設(shè)置定時(shí)器 $('#flash').hover(function(){ //設(shè)置鼠標(biāo)移入移出事件 clearInterval(timer); },function(){ timer = setInterval(run,1000); }) $('#flash ul li').mouseenter(function(){ //設(shè)置移入圓點(diǎn)事件 count = $(this).index(); count = count ==5?0:count; $('#flash img').eq(count).fadeIn(300).siblings('img').fadeOut(300); $('#flash ul li').eq(count).css('background','#f40').siblings('li').css('background','#fff'); }) $('#flash .right').click(function(){ //設(shè)置右鍵按鈕點(diǎn)擊事件 run(); }) $('#flash .left').click(function(){ //設(shè)置左鍵按鈕點(diǎn)擊事件 reverserun(); }) </script> </body> </html>
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun,測(cè)試一下運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery 實(shí)現(xiàn)輪播圖詳解及實(shí)例代碼
- 利用jquery寫(xiě)的左右輪播圖特效
- jquery實(shí)現(xiàn)左右無(wú)縫輪播圖
- jQuery實(shí)現(xiàn)輪播圖及其原理詳解
- jQuery插件slides實(shí)現(xiàn)無(wú)縫輪播圖特效
- jquery實(shí)現(xiàn)左右滑動(dòng)式輪播圖
- jQuery自適應(yīng)輪播圖插件Swiper用法示例
- JQuery和html+css實(shí)現(xiàn)帶小圓點(diǎn)和左右按鈕的輪播圖實(shí)例
- jquery實(shí)現(xiàn)輪播圖特效
- jquery實(shí)現(xiàn)無(wú)縫輪播圖
相關(guān)文章
jquery數(shù)組過(guò)濾篩選方法grep()簡(jiǎn)介
這篇文章主要介紹了jquery數(shù)組過(guò)濾篩選方法grep()簡(jiǎn)介,需要的朋友可以參考下2014-06-06細(xì)說(shuō)瀏覽器特性檢測(cè)(2)-通用事件檢測(cè)
在上一篇中介紹了jQuery1.4版本新增的幾個(gè)瀏覽器特性檢測(cè)方案和具體的目的,本文將以事件為中心,介紹一個(gè)較為完整、通用的事件檢測(cè)方案。2010-11-11jQuery實(shí)現(xiàn)簡(jiǎn)單的計(jì)時(shí)器功能實(shí)例分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)簡(jiǎn)單的計(jì)時(shí)器功能,結(jié)合實(shí)例形式分析了jQuery實(shí)現(xiàn)倒計(jì)時(shí)60秒的具體操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-08-08jQuery實(shí)現(xiàn)的感應(yīng)鼠標(biāo)懸停圖片色彩漸顯效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)的感應(yīng)鼠標(biāo)懸停圖片色彩漸顯效果,涉及jQuery中hover、find、css等方法的使用技巧,需要的朋友可以參考下2015-03-03jquery實(shí)現(xiàn)網(wǎng)站超鏈接和圖片提示效果
超鏈接提示效果可以通過(guò)title實(shí)現(xiàn);圖片提示效果可以通過(guò)alt實(shí)現(xiàn),本文將會(huì)介紹下使用jquery實(shí)現(xiàn)超鏈接與圖片提示效果,感興趣的朋友們可以參考下哈2013-03-03jQuery通過(guò)Ajax返回JSON數(shù)據(jù)
最近在使用JQuery的ajax方法時(shí),要求返回的數(shù)據(jù)為json數(shù)據(jù),在處理的過(guò)程中遇到下面的幾個(gè)問(wèn)題,那就是采用不同的方式來(lái)生成json數(shù)據(jù)的時(shí)候,在$.ajax方法中應(yīng)該是如何來(lái)處理的,下面依次來(lái)進(jìn)行說(shuō)明。2015-04-04jQuery創(chuàng)建自己的插件(自定義插件)的方法
在該系列之前的文章使用 jQuery:UI 項(xiàng)目中,我介紹了使用 jQuery 代碼中的插件來(lái)提高 web 應(yīng)用程序的效率。2010-06-06