


This time I will bring you jquery to implement the automatic carousel switching function with index buttons. What are the things to note in jquery to implement the automatic carousel switching function with index buttons. The following is a practical case. Let’s take a look. one time.
Introduce CSS styles in the head area:
<link> <link>The jquery shared with you has an index button and the automatic carousel switching special effect code is as follows
nbsp;html> <meta> <meta> <meta> <title>腾讯微云首页jquery焦点图</title> <link> <link> <!--[if IE 6]><script type="text/javascript">try{document.execCommand('BackgroundImageCache',false,true);}catch(e){}</script><![endif]--> <p> </p><p> </p><p> </p><p> </p><p> <img src="/static/imghwm/default1.png" data-src="images/banner4.jpg" class="lazy" alt="jquery implements automatic carousel switching function with index button" > </p><p> </p><h3 id="微云-生活精彩">微云,生活精彩</h3> <p>收录生活中的点点滴滴,精彩从此刻开始!</p> <a><span>马上下载 </span><i></i></a> <p> <img src="/static/imghwm/default1.png" data-src="images/banner3.jpg" class="lazy" alt="jquery implements automatic carousel switching function with index button" > </p><p> </p><h3 id="微云-生活精彩">微云,生活精彩</h3> <p>收录生活中的点点滴滴,精彩从此刻开始!</p> <a><span>马上下载 </span><i></i></a> <p> <img src="/static/imghwm/default1.png" data-src="images/banner2.jpg" class="lazy" alt="jquery implements automatic carousel switching function with index button" > </p><p> </p><h3 id="微云-生活精彩">微云,生活精彩</h3> <p>收录生活中的点点滴滴,精彩从此刻开始!</p> <a><span>马上下载 </span><i></i></a> <p> <img src="/static/imghwm/default1.png" data-src="images/banner1.jpg" class="lazy" alt="jquery implements automatic carousel switching function with index button" > </p><p> </p><h3 id="微云-生活精彩">微云,生活精彩</h3> <p>收录生活中的点点滴滴,精彩从此刻开始!</p> <a><span>马上下载</span> <i></i></a> <p> <a> <span></span> <span></span> </a> <a> <span></span> <span></span> </a> <a> <span></span> <span></span> </a> <a> <span></span> <span></span> </a> </p> <script></script> <script> var glume = function(banners_id, focus_id){ this.$ctn = $('#' + banners_id); this.$focus = $('#' + focus_id); this.$adLis = null; this.$btns = null; this.switchSpeed = 5;//自动播放间隔(s) this.defOpacity = 1; this.crtIndex = 0; this.adLength = 0; this.timerSwitch = null; this.init(); }; glume.prototype = { fnNextIndex:function(){ return (this.crtIndex >= this.adLength-1)?0:this.crtIndex+1; }, //动画切换 fnSwitch:function(toIndex){ if(this.crtIndex==toIndex){return;} this.$adLis.css('zIndex', 0); this.$adLis.filter(':eq('+this.crtIndex+')').css('zIndex', 2); this.$adLis.filter(':eq('+toIndex+')').css('zIndex', 1); this.$btns.removeClass('on'); this.$btns.filter(':eq('+toIndex+')').addClass('on'); var me = this; $(this.$adLis[this.crtIndex]).animate({ opacity: 0 }, 1000, function() { me.crtIndex = toIndex; $(this).css({ opacity: me.defOpacity, zIndex: 0 }); }); }, fnAutoPlay:function(){ this.fnSwitch(this.fnNextIndex()); }, fnPlay:function(){ var me = this; me.timerSwitch = window.setInterval(function() { me.fnAutoPlay(); },me.switchSpeed*1000); }, fnStopPlay:function(){ window.clearTimeout(this.timerSwitch); this.timerSwitch = null; }, init:function(){ this.$adLis = this.$ctn.children(); this.$btns = this.$focus.children(); this.adLength = this.$adLis.length; var me = this; //点击切换 this.$focus.on('click', 'a', function(e) { e.preventDefault(); var index = parseInt($(this).attr('data-index'), 10) me.fnSwitch(index); }); this.$adLis.filter(':eq('+ this.crtIndex +')').css('zIndex', 2); this.fnPlay(); //hover时暂停动画 this.$ctn.hover(function() { me.fnStopPlay(); }, function() { me.fnPlay(); }); if($.browser.msie && $.browser.version < 7) { this.$btns.hover(function() { $(this).addClass('hover'); },function() { $(this).removeClass('hover'); }); } } }; var player1 = new glume('_banners', '_focus'); </script>I believe you have mastered it after reading the case in this article Method, for more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:
jQuery realizes the picture carousel slide effect
jQuery animation effect picture carousel realization (attached Code)
The above is the detailed content of jquery implements automatic carousel switching function with index button. For more information, please follow other related articles on the PHP Chinese website!

实现方法:1、用“$("img").delay(毫秒数).fadeOut()”语句,delay()设置延迟秒数;2、用“setTimeout(function(){ $("img").hide(); },毫秒值);”语句,通过定时器来延迟。

修改方法:1、用css()设置新样式,语法“$(元素).css("min-height","新值")”;2、用attr(),通过设置style属性来添加新样式,语法“$(元素).attr("style","min-height:新值")”。

区别:1、axios是一个异步请求框架,用于封装底层的XMLHttpRequest,而jquery是一个JavaScript库,只是顺便封装了dom操作;2、axios是基于承诺对象的,可以用承诺对象中的方法,而jquery不基于承诺对象。

增加元素的方法:1、用append(),语法“$("body").append(新元素)”,可向body内部的末尾处增加元素;2、用prepend(),语法“$("body").prepend(新元素)”,可向body内部的开始处增加元素。

在jquery中,apply()方法用于改变this指向,使用另一个对象替换当前对象,是应用某一对象的一个方法,语法为“apply(thisobj,[argarray])”;参数argarray表示的是以数组的形式进行传递。

删除方法:1、用empty(),语法“$("div").empty();”,可删除所有子节点和内容;2、用children()和remove(),语法“$("div").children().remove();”,只删除子元素,不删除内容。

去掉方法:1、用“$(selector).removeAttr("readonly")”语句删除readonly属性;2、用“$(selector).attr("readonly",false)”将readonly属性的值设置为false。

on()方法有4个参数:1、第一个参数不可省略,规定要从被选元素添加的一个或多个事件或命名空间;2、第二个参数可省略,规定元素的事件处理程序;3、第三个参数可省略,规定传递到函数的额外数据;4、第四个参数可省略,规定当事件发生时运行的函数。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
