jQuery focus map plugin SaySlide_jquery
先来介绍SaySlide 2.0支持自定义如下功能:
- 1、上下左右方向播放以及jQuery的fadeOut、slideUp、hide效果;
- 2、自动播放时间间隔和动画播放的的速度;
- 3、是否显示标题;
- 4、是否在新窗口打开链接;
- 5、是否显示底部半透明背景;
- 6、按钮在底部显示的位置(左中右);
- 7、按钮默认背景色;
- 8、按钮激活状态颜色;
- 9、设置标题文字的样式;
- 10、触发按钮的事件;
下面就是重点的代码,分享给大家供大家参考,具体代码如下
(function($){ $.fn.saySlide=function(options){ var defaults={ autoTime:3000,//自动播放时间间隔 speed:500,//切换速度 autodir:'RL',//自动播放方向,LR左到右,RL右到左,TB上到下,BT下到上, jQuery自带的动画:jq.fadeOut , jq.slideUp , jq.hide isTitle:false,//是否显示标题 isBlank:true,//是否在新窗口打开链接 isBottombg:true,//是否显示底部半透明背景,该设置只有在isTitle为false生效 defaultBg:"#999999",//定义底部按钮默认颜色 currentBg:"#ffffff",//定义底部按钮激活状态颜色 btnAlign:"center",//按钮左中右位置,left,center,right fontSize:"14px" }; var _this=$(this), len=_this.children().length, _thisChildren; options.Width=_this.width() || 0; options.Height=_this.height() || 0; options.Imgs=options.ImgsO=_this.children(); options.nowImg=0; options.isLink = $(options.Imgs[0]).attr("href") === undefined ? false : true; //根据第一张图片是否有href属性来判断是否给图片加上链接 var options=$.extend(defaults,options); switch(options.autodir){ case "LR":options.pos="right";break; case "RL":options.pos="left";break; case "BT":options.pos="top";break; case "TB":options.pos="bottom";break; default: if(/jq\\./.test(options.autodir)){ options.jq=options.autodir.slice(3); options.autodir="jq"; }else{ alert("autodir参数不正确"); } } var SaySlide=function(opt){ this.opt=opt; } SaySlide.prototype={ _init:function(){ this.BulkImgs(); this.AutoPlay(); this.PausePlay(); this.BtnClick(); }, BoxBtn:function(){ var me=this.opt, boxHtml=''; for(var i=0;i<len;i++){ var bg=i==0?me.currentBg:me.defaultBg; boxHtml+='<i style="background-color:'+ bg +'" index="'+ i +'"></i>'; } var textAlign=me.isTitle==true ? "right" : me.btnAlign; boxHtml='<div class="saySlide-bottom-btn" style="text-align:'+ textAlign +'"><span>'+ boxHtml +'</span></div>'; return boxHtml; }, BulkImgs:function(){ var me=this.opt, ImgsArr=new Array; for(var i=0;i<len;i++){ if(me.isLink===true){ var link=$(me.Imgs[i]).attr({"width":me.Width,"height":me.Height}).attr("href"); $(me.Imgs[i]).removeAttr("href"); ImgsArr[i]="<a href='"+ link +"' index='"+ i +"'>"+me.Imgs[i].outerHTML+'</a>'; }else{ $(me.Imgs[i]).attr({"width":me.Width,"height":me.Height}); ImgsArr[i]="<a index='"+ i +"'>"+me.Imgs[i].outerHTML+'</a>'; } } if(me.autodir=="LR" || me.autodir=="TB" || me.autodir=="jq"){ var ImgsStr=ImgsArr.reverse().join(''); }else{ var ImgsStr=ImgsArr.join(''); } _this.html(ImgsStr); me.Imgs=_this.children(); if(me.autodir!="jq"){ _this.wrapInner("<div class='saySlide-box' />"); _thisChildren=_this.children("div.saySlide-box"); var divWidth=me.autodir=="LR" || me.autodir=="RL" ? me.Width*len :me.Width; _thisChildren.width(divWidth).css(me.pos,"0"); }else{ _this.addClass("saySlide-fade"); } var opacityBg=me.isBottombg===true || me.isTitle===true ? '<div class="saySlide-opacity-bg"></div>' : '';//如果有标题,则透明背景强制显示 _this.append(this.BoxBtn() + opacityBg); me.BtnArr=_this.find("i"); if(me.isTitle===true){ this.BuildTitle(); } }, /* 构造标题 */ BuildTitle:function(){ var _w=14*len, me=this.opt; _w=me.Width - _w - 20 - 40; _this.append('<div class="saySlide-title" />'); me.titleBox=_this.children("div.saySlide-title").css({"font-size":me.fontSize,width:_w}); me.titleBox.text($(me.ImgsO[0]).attr("alt")); }, /* 自动播放 */ AutoPlay:function(){ var self=this, me=this.opt; self.t=setInterval(function(){ self.PicPlay(); },me.autoTime); }, /* 鼠标经过时清除定时 */ PausePlay:function(){ var self=this; _this.hover(function(){ clearInterval(self.t); },function(){ self.AutoPlay(); }); }, PicPlay:function(){ var me=this.opt; if(me.autodir=="RL" || me.autodir=="BT"){ this.MoveV(me.autodir); }else if(me.autodir=="LR" || me.autodir=="TB"){ this.MoveH(me.autodir); }else if(me.autodir=="jq"){ this.MovejQ(); } var current=me.nowImg > len-1 ? 0 : me.nowImg; $(me.BtnArr[current]).css("background-color",me.currentBg).siblings().css("background-color",me.defaultBg); if(me.isTitle===true){ me.titleBox.text($(me.ImgsO[current]).attr("alt")); } }, /* 点击标签按钮 */ BtnClick:function(){ var self=this, me=this.opt; _this.delegate("i","click",function(){ var clicked=parseInt($(this).attr("index")); me.nowImg=clicked; if(me.autodir=="RL" || me.autodir=="BT"){ var prevImgs=_thisChildren.find("a[index='"+ clicked +"']").prevAll(); prevImgs=$.makeArray(prevImgs).reverse(); _thisChildren.css(me.pos,"0"); $(prevImgs).appendTo(_thisChildren); }else if(me.autodir=="LR" || me.autodir=="TB"){ var prevImgs=_thisChildren.find("a[index='"+ clicked +"']").nextAll(); _thisChildren.css(me.pos,"0"); $(prevImgs).prependTo(_thisChildren); }else if(me.autodir=="jq"){ var prevImgs=_this.find("a[index='"+ clicked +"']").nextAll("a"); prevImgs.prependTo(_this); } $(this).css("background-color",me.currentBg).siblings().css("background-color",me.defaultBg); }); }, /* 从右到左播放 、 从下到上播放 */ MoveV:function(type){ var me=this.opt, current; me.nowImg = me.nowImg+1 > len ? 1 : me.nowImg+1; current = me.nowImg - 1; if(type=="RL"){ _thisChildren.animate({"left":"-"+me.Width},me.speed,function(){ $(me.Imgs[current]).appendTo($(this)); $(this).css("left","0"); }); }else if(type=="BT"){ _thisChildren.animate({"top":"-"+me.Height},me.speed,function(){ $(me.Imgs[current]).appendTo($(this)); $(this).css("top","0"); }); } }, /* 淡入淡出 */ MovejQ:function(){ var me=this.opt, current; me.nowImg = me.nowImg+1 > len-1 ? 0 : me.nowImg+1; current = len - me.nowImg == len ? 0 : len-me.nowImg; var arg1=me.speed; var arg2=function(){$(this).prependTo(_this).show();}; if(me.jq=="fadeOut"){ $(me.Imgs[current]).fadeOut(arg1,arg2); }else if(me.jq=="hide"){ $(me.Imgs[current]).hide(arg1,arg2); }else if(me.jq=="slideUp"){ $(me.Imgs[current]).slideUp(arg1,arg2); }else{ return ; } }, /* 从左到右播放 、 从上到下播放 */ MoveH:function(type){ var me=this.opt, current; me.nowImg = me.nowImg+1 > len-1 ? 0 : me.nowImg+1; current = len - me.nowImg == len ? 0 : len-me.nowImg; if(type=="LR"){ _thisChildren.animate({"right":"-"+me.Width},me.speed,function(){ $(me.Imgs[current]).prependTo($(this)); $(this).css("right","0"); }); }else if(type=="TB"){ _thisChildren.animate({"bottom":"-"+me.Height},me.speed,function(){ $(me.Imgs[current]).prependTo($(this)); $(this).css("bottom","0"); }); } } } var _SaySlide=new SaySlide(options); _SaySlide._init(); } })(jQuery);
以上就是焦点图插件SaySlide的代码,对关键代码进行注释,希望对大家的学习有所帮助。

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

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



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

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

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

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

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
