


Sharing of jquery version carousel effect and extend extension examples
This article mainly introduces the effect of the jquery version of the carousel image in detail, as well as the related information of extend. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
The specific code is as follows
<!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>
Related recommendations:
Detailed example of jquery to achieve the effect of the left and right carousel image
The above is the detailed content of Sharing of jquery version carousel effect and extend extension examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

The relationship between the number of Oracle instances and database performance Oracle database is one of the well-known relational database management systems in the industry and is widely used in enterprise-level data storage and management. In Oracle database, instance is a very important concept. Instance refers to the running environment of Oracle database in memory. Each instance has an independent memory structure and background process, which is used to process user requests and manage database operations. The number of instances has an important impact on the performance and stability of Oracle database.

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:
