jquery版輪播圖效果與extend擴充實例分享
本文主要為大家詳細介紹了jquery版輪播圖效果,以及extend擴展的相關資料,具有一定的參考價值,有興趣的小伙伴們可以參考一下,希望能幫助到大家。
具體程式碼如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ margin:0; padding:0; font-size:14px; -webkit-user-select:none; } ul,li{ list-style:none; } img{ display:block; border:none; } a{ text-decoration: none; } .banner{ position:relative; margin:10px auto; width:1000px; height:300px; overflow:hidden; } .bannerInner{ width:100%; height:100%; background:url("../img/default.gif") no-repeat center center; } .bannerInner p{ position:absolute; top:0; left:0; z-index:0; width:100%; height:100%; opacity: 0; filter:alpha(opacity=0); } .bannerInner p img{ display:none; width:100%; height:100%; } .banner .bannerTip{ position:absolute; right:20px; bottom:20px; z-index:10; overflow:hidden; } .banner .bannerTip li{ float:left; margin-left:10px; width:18px; height:18px; background:lightblue; border-radius:50%; cursor:pointer; } .banner .bannerTip li.bg{ background:orange; } .banner a{ display:none; position:absolute; top:50%; margin-top:-22.5px; z-index:10; width:30px; height:45px; opacity: 0.5; filter:alpha(opacity=50); background-image:url('../img/pre.png'); } .banner a.bannerLeft{ left:20px; background-position:0 0; } .banner a.bannerRight{ right:20px; background-position:-50px 0; } .banner a:hover{ opacity: 1; filter:alpha(opacity=100); } </style> </head> <body> <p class='banner' id='bannerFir'> <p class='bannerInner'> <p><img src="" alt="" trueImg='img/banner1.jpg'></p> <p><img src="" alt="" trueImg='img/banner2.jpg'></p> <p><img src="" alt="" trueImg='img/banner3.jpg'></p> <p><img src="" alt="" trueImg='img/banner4.jpg'></p> </p> <ul class='bannerTip'> <li class='bg'></li> <li></li> <li></li> <li></li> </ul> <a href="javascript:;" rel="external nofollow" rel="external nofollow" class='bannerLeft'></a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" class='bannerRight'></a> </p> <script> jQuery.fn.extend({ banner:myBanner }) //通过jQuery选择器或者筛选的方法获取到的jQuery集合是不存在dom映射机制的,之前获取到的dom集合,之后再页面中HTML结构改变了,集合中的内容不会跟着自动发生变化(JS获取的元素集合有DOM映射的机制) function myBanner(selector,ajaxURL,interval){ var $banner = $("#"+selector); var $bannerInner = $banner.children(".bannerInner"),$pList = null,$imgList = null; var $bannerTip = $banner.children(".bannerTip"),$oLis = null var $bannerLeft = $banner.children(".bannerLeft"),$bannerRight = $banner.children(".bannerRight") //1、Ajax读取数据 var jsonData = null; $.ajax({ url:ajaxURL+"?_="+Math.random(), type:'get', dataType::"json", async:false,//当前的请求是同步的 success:function(data){ jsonData = data; } }) //2、实现数据的绑定 function bindData(){ var str = "",str2 = ""; if(jsonData){ //原生的jsonData使用$.each() $.each(jsonData,function(index,item){ str+='<p><img src="" alt="" trueImg="'+item["img"]+'"></p>'; index===0?str2+='<li class="bg"></li>':str2+='<li></li>' }) $bannerInner.html(str); $bannerTip.html(str2); $pList = $bannerInner.children("p") $imgList = $bannerInner.find('img') $oLis = $bannerTip.children("li") } } //3、实现图片的延迟加载 window.setTimeout(lazyImg,500); function lazyImg(){ //jquery元素集合 直接写$imgList.each() $imgList.each(function(index,item){ var _this = this; var oImg = new Image; oImg.src = $(this).attr("trueImg");//$(this)等价于$(item) oImg.onload = function(){ $(_this).prop('src',this.src).css("display","block")//内置属性使用prop } }) $pList.eq(0).css("zIndex",1).animate({opacity:1},300); } //封装一个轮播图切换的效果 function changeBanner(){ var $curp = $pList.eq(step); $curp.css("zIndex",1).siblings().css("zIndex",0); $curp.animate({opacity:1},300,function(){ $(this).siblings().css("opacity",0) }) $oLis.eq(step).addClass("bg").siblings().removeClass('bg') } //4、实现自动轮播 interval = interval || 3000; var step = 0,autoTimer = null; autoTimer = window.setInterval(autoMove,interval) function autoMove(){ if(step === jsonData.length-1){ step = -1; } step++; changeBanner(); } //5、控制左右按钮的显示隐藏和自动轮播的开始和暂停 $banner.on('mouseover',function(){ window.clearInterval(autoTimer); $bannerLeft.css("display","block") $bannerRight.css("display","block") }).on('mouseout',function(){ autoTimer = window.setInterval(autoMove,interval); $bannerLeft.css("display","none") $bannerRight.css("display","none") }) //6、实现焦点切换 $oLis.on('click',function(){ step = $(this).index(); changeBanner(); }) //7、实现左右切换 $bannerRight.on('click',autoMove); $bannerLeft.on('click',function(){ if(step===0){ step = jsonData.length; } step--; changeBanner(); }); } //外部使用 $().banner("bannerFir","json/banner.txt",1000) </script> </body> </html>
相關推薦:
關於JQuery和html+css實作帶小圓點和左右按鈕的輪播圖分享
以上是jquery版輪播圖效果與extend擴充實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

jQuery中如何使用PUT請求方式?在jQuery中,發送PUT請求的方法與發送其他類型的請求類似,但需要注意一些細節和參數設定。 PUT請求通常用於更新資源,例如更新資料庫中的資料或更新伺服器上的檔案。以下是在jQuery中使用PUT請求方式的具體程式碼範例。首先,確保引入了jQuery庫文件,然後可以透過以下方式發送PUT請求:$.ajax({u

標題:jQuery小技巧:快速修改頁面所有a標籤的文字在網頁開發中,我們經常需要對頁面中的元素進行修改和操作。使用jQuery時,有時候需要一次修改頁面中所有a標籤的文字內容,這樣可以節省時間和精力。以下將介紹如何使用jQuery快速修改頁面所有a標籤的文本,同時給出具體的程式碼範例。首先,我們需要引入jQuery庫文件,確保在頁面中引入了以下程式碼:<

標題:使用jQuery修改所有a標籤的文字內容jQuery是一款受歡迎的JavaScript庫,被廣泛用於處理DOM操作。在網頁開發中,經常會遇到需要修改頁面上連結標籤(a標籤)的文字內容的需求。本文將介紹如何使用jQuery來實現這個目標,並提供具體的程式碼範例。首先,我們需要在頁面中引入jQuery庫。在HTML檔案中加入以下程式碼:

jQuery如何移除元素的height屬性?在前端開發中,經常會遇到需要操作元素的高度屬性的需求。有時候,我們可能需要動態改變元素的高度,而有時候又需要移除元素的高度屬性。本文將介紹如何使用jQuery來移除元素的高度屬性,並提供具體的程式碼範例。在使用jQuery操作高度屬性之前,我們首先需要了解CSS中的height屬性。 height屬性用於設定元素的高度

jQuery是一種流行的JavaScript庫,被廣泛用於處理網頁中的DOM操作和事件處理。在jQuery中,eq()方法是用來選擇指定索引位置的元素的方法,具體使用方法和應用場景如下。在jQuery中,eq()方法選擇指定索引位置的元素。索引位置從0開始計數,即第一個元素的索引是0,第二個元素的索引是1,依此類推。 eq()方法的語法如下:$("s

如何判斷jQuery元素是否具有特定屬性?在使用jQuery操作DOM元素時,常會遇到需要判斷元素是否具有某個特定屬性的情況。在這種情況下,我們可以藉助jQuery提供的方法來輕鬆實現這項功能。以下將介紹兩種常用的方法來判斷一個jQuery元素是否具有特定屬性,並附上具體的程式碼範例。方法一:使用attr()方法和typeof運算子//判斷元素是否具有特定屬

jQuery是一個受歡迎的JavaScript函式庫,廣泛用於網頁開發。在網頁開發過程中,經常需要透過JavaScript動態地在表格中新增一行。本文將介紹如何使用jQuery為表格新增一行,並提供具體的程式碼範例。首先,我們需要在HTML頁面中引入jQuery函式庫。可以透過以下程式碼在標籤中引入jQuery庫:

Oracle實例數量與資料庫效能關係Oracle資料庫是業界知名的關係型資料庫管理系統之一,廣泛應用於企業級的資料儲存與管理。在Oracle資料庫中,實例是一個非常重要的概念。實例是指Oracle資料庫在記憶體中的運作環境,每個實例都有獨立的記憶體結構和後台進程,用於處理使用者的請求和管理資料庫的操作。實例數量對於Oracle資料庫的效能和穩定性有著重要的影響。
