/** * 欢迎使用 sliderplay 幻灯片『焦点图』插件 * * jquery sliderplay plugin * ========================================〓说明〓======================================================== * jquery幻灯片插件,基本能满足你在网页上使用幻灯片(焦点图)效果。兼容ie6/ie7/ie8/ie9,firefox,chrome,opera等主流浏览器。 * 使用极其方便、简单,外观样式可以自定义,具体定义样式方法和设置其他参数请参见demo文件 * ======================================================================================================== * @name jquery.sliderplay.js * @version 2.0 * @author mr.rong * @date 2013-12-10 * @email:506713930@qq.com * 欲索取最新版本sliderplay或是报告bug,请发送email至 506713930@qq.com * * 请尊重他人的劳动作品! 如蒙转载请注明出处 **/ ;(function(window,$){$.fn.sliderplay=function(options){options=$.extend({speed:700,timeout:3000,movetype:'opacity',direction:'left',mouseevent:'click',isshowtitle:true,isshowbtn:true},options);var osliderplaybox=this;var asliderplayimg=osliderplaybox.find('img');var asliderplayitem=osliderplaybox.children();var size=asliderplayimg.length;var ispeed=options.speed;var itimeout=options.timeout;var smovetype=options.movetype;var sdirection=options.direction;var smouseevent=options.mouseevent;var bisshowtitle=options.isshowtitle;var bisshowbtn=options.isshowbtn;var iimgwidth=asliderplayimg.width();var iimgheight=asliderplayimg.height();var icurindex=0;var iprevindex=0;var ibtnindex=0;var oautotimer=null;var otimer=null;var flag=false;var autoplay=function(){};var move=function(){};if(smouseevent!='mouseover'&&smouseevent!='click'){smouseevent='click'};if(sdirection!='left'&&sdirection!='top'){smouseevent='left'};if(smovetype!='randommove'&&smovetype!='moveto'&&smovetype!='opacity'){smovetype='moveto'}!function setdefaultstyle(){osliderplaybox.addclass('sliderplay');osliderplaybox.css({width:iimgwidth,height:iimgheight,visibility:'visible'})}();if(bisshowbtn==true){var sbtnhtml='
 ';for(var i=2;i<=size;i++){sbtnhtml+=''+' '+''};sbtnhtml+='
';this.append(sbtnhtml);var asliderplaybtn=this.find('.sliderplay-btn').find('span')};if(bisshowtitle){this.append('
'+asliderplayimg.attr('alt')+'
');var osliderplaytitle=this.find('.sliderplay-title')};switch(smovetype){case'moveto':setmoveto();break;case'opacity':setoptity();break;case'randommove':setrandommove();break};function addevent(move,autoplay){if(bisshowbtn){if(smouseevent=='click'){asliderplaybtn.on('click',function(e){e.preventdefault();oautotimer&&clearinterval(oautotimer);ibtnindex=icurindex=$(this).index();move()})}else{asliderplaybtn.mouseenter(function(){oautotimer&&clearinterval(oautotimer);ibtnindex=icurindex=$(this).index();otimer=settimeout(move,200)}).mouseleave(function(){cleartimeout(otimer)})}};osliderplaybox.hover(function(){oautotimer&&clearinterval(oautotimer)},function(){oautotimer=setinterval(autoplay,itimeout)})};function setattr(index){osliderplaytitle&&osliderplaytitle.html(asliderplayimg.eq(index).attr('alt'));asliderplaybtn&&asliderplaybtn.removeclass('current').eq(index).addclass('current')};function setmoveto(){var style='';if(sdirection=='left'){style='width:'+(size+1)*iimgwidth+'px'}else{style='height:'+(size+1)*iimgheight+'px'};osliderplaybox.css('overflow','hidden');asliderplayitem.wrapall('
');asliderplayimg.css('float','left');var osliderplaymain=osliderplaybox.find('.sliderplaymain');var data={};move=function(){if(sdirection=='left'){data['left']=-iimgwidth*icurindex}else{data['top']=-iimgheight*icurindex};osliderplaymain.animate(data,ispeed,function(){if(flag){if(sdirection=='left'){osliderplaymain.css('left',0)}else{osliderplaymain.css('top',0)};icurindex=0;osliderplaymain.children().last().remove();flag=false}});setattr(ibtnindex)};autoplay=function(){ibtnindex=++icurindex;if(icurindex==size){asliderplayitem.eq(0).clone().appendto(osliderplaymain);flag=true;ibtnindex=0};move()};addevent(move,autoplay);oautotimer=setinterval(autoplay,itimeout)};function setoptity(){asliderplayimg.css({position:'absolute',left:0,top:0,display:'none'}).first().show();move=function(){setattr(icurindex);asliderplayimg.stop().fadeout(ispeed).eq(icurindex).fadein(ispeed);iprevindex=icurindex};autoplay=function(){icurindex++;if(icurindex==size){icurindex=0};move()};addevent(move,autoplay);oautotimer=setinterval(autoplay,itimeout)};function setrandommove(){osliderplaybox.css('overflow','hidden');asliderplayimg.css({position:'absolute',left:0,top:0,zindex:0}).first().css({zindex:1});var dir=[0,1,2,3];move=function(){var oprev=asliderplayimg.eq(iprevindex);var o=asliderplayimg.eq(icurindex);var data={opacity:0};if(dir.length==0){dir=[0,1,2,3]};if(dir.length==4){dir.sort(function(){return math.random()>0.5?1:-1})};switch(dir.shift()){case 0:data['top']=-iimgheight;break;case 1:data['left']=iimgwidth;break;case 2:data['top']=iimgheight;break;default:data['left']=-iimgwidth};setattr(icurindex);oprev.css('zindex',2).animate(data,ispeed,function(){oprev.css({zindex:0,opacity:1,top:0,left:0})});o.css('zindex',1);iprevindex=icurindex};autoplay=function(){icurindex++;if(icurindex==size){icurindex=0};move()};addevent(move,autoplay);oautotimer=setinterval(autoplay,itimeout)};return osliderplaybox}})(window,jquery);