/** * Author: 张中乐 * Email: sjz20072-304@163.com * Update: 2014.5.13 */ ;(function($){ //个人插件 start $.fn.extend({ /** * 功能介绍:标签切换tab * 参数介绍: * myevent:'click', 默认为单击click事件,可修改 * contentId:'', 默认为空,可切换内容父级标签ID,选填项 * contentCss:'' 默认为空,可切换内容标签样式,必填项 * titleOff:'', 默认为空,提示标题常状态样式,选填项 * titleOn:'', 默认为空,提示标题当前选中状态样式,选填项 * btn:'li' 默认为li标签做为点击按钮,可修改 *--------------------------------------- * Update: 2014.4.30 */ 'tab':function(options){ var p_self=$(this); var last=null; options=$.extend({ myevent:'click', contentId:'', contentCss:'', titleOff:'', titleOn:'', animteCss:'fadeInRight', active:false, btn:'li' },options); p_self.children(options.btn).on(options.myevent,function(){ if(last==$(this).index()) return false; if(options.active){ p_self.children(options.btn).removeClass(options.titleOn) $(this).addClass(options.titleOn); }else{ p_self.children(options.btn).attr('class',options.titleOff) $(this).attr('class',options.titleOn); } if(options.contentId){ $(options.contentId+' '+options.contentCss).eq($(this).index()).show().siblings().hide(); }else{ $(options.contentCss).hide(); $(options.contentCss).eq($(this).index()).show(); if(options.animteCss){ $(options.contentCss).removeClass(options.animteCss); $(options.contentCss).eq($(this).index()).addClass(options.animteCss); } } last=$(this).index(); }); return this; }, /** * 功能介绍:imitate Select 模拟下拉框 * 参数介绍: * sub_ul:'ul', 默认下拉框父标签为‘ul’,可修改为其他标签 * sub_li:'li', 默认下拉框子标签为‘li’,可修改为其他标签 * myevent:'click', 默认事件为‘click’,可修改 * selected:1, 默认选中下拉菜单第一项,可修改为1,2,3... ;若为last,选中最后一项 * speed:100, * clickIsHide 默认为true,点击后下拉框是否消失 *--------------------------------------- * Update: 2014.4.30 */ 'imiSelect':function(options){ var clickone_tid = []; var p_self=$(this); var ele={} options=$.extend({ sub_ul:'ul', sub_li:'li', myevent:'click', selected:1, speed:100, clickIsHide:true, parent_css:'.zselect', box:'.zse_ul' },options); //显示和隐藏下拉框 p_self.on(options.myevent,function(){ $(options.box).slideUp(); $(this).addClass("zfl_white"); $(options.parent_css).css('zIndex','1'); $(this).css('zIndex','22'); clearTimeout(clickone_tid[0]); self_=this; clickone_tid[0]=setTimeout(function(){ $(self_).find(options.sub_ul+':eq(0)').slideToggle(options.speed?'fast':options.speed); },200); }); //默认选中第N项 ele.ul=p_self.find(options.sub_ul+':eq(0)'); ele.li=p_self.find(options.sub_ul+':eq(0)').find(options.sub_li); if(options.selected){ if(options.selected'+parseInt(i+1)+''); }else{ $(notConf.point).append('<'+notConf.tmp+' class="'+options.pointOff+'">'); } }; $(notConf.point).find(notConf.tmp).each(function(index){ $(this).on('click',function(){ if(notConf.count!=index){ move_right(index); } $(this).attr('class',options.pointOn).siblings().attr('class',options.pointOff); notConf.count=index; }); }); //添加当前按钮样式 function cur_btn(){ $(notConf.point).find(notConf.tmp).eq(notConf.count).attr('class',options.pointOn).siblings().attr('class',options.pointOff); } if(options.isPoint){ notConf.point.show(); } //根据窗口改变重新初始化 function setwindow(){ notConf.width=$(window).width(); //notConf.height=$(window).height(); if(notConf.width<=options.minW){ notConf.width=options.minW; } if(!options.isfull){ notConf.width=options.minW; } //options.bg.height(notConf.height+'px'); notConf.content.width(notConf.width); notConf.mid.html(notConf.middle.html()); notConf.middle.width(notConf.content.length*notConf.width); notConf.mid.width(notConf.content.length*notConf.width); if(notConf.flag){ //保留注释,待更新在浏览器大小改变时,不改变当前图片 //notConf.mid.css('left',-notConf.width*notConf.count+'px'); //notConf.middle.css('left',notConf.width*(notConf.content.length-notConf.count)+'px'); setone(); notConf.lastW=notConf.width; //notConf.lastH=notConf.height; notConf.flag=0; } } setwindow(); //校对轨道 function check(f){ //f值为1:校对向左滑动轨道,f值为0或空:校对向右滑动轨道 if(f){ var site=(notConf.mid.position().left<=0?notConf.mid.position().left*-1:notConf.mid.position().left*1)/notConf.width; notConf.middle.css('left',(notConf.content.length-site)*notConf.width+'px'); }else{ var site=(notConf.mid.position().left<=0?notConf.mid.position().left*-1:notConf.mid.position().left*1)/notConf.width; notConf.middle.css('left',(notConf.content.length+site)*notConf.width*-1+'px'); } } //初始化被克隆和克隆内容的位置,以满足左右按钮条件使点击左右滑动 function setone(){ notConf.middle.css('left',notConf.content.length*notConf.width*-1+'px'); notConf.mid.css('left',0+'px'); notConf.count=0; cur_btn(); } setone(); //左滑动 function move_left(){ if(notConf.isbottom){ notConf.isbottom=0; check(1); } if(notConf.middle.position().left<=(-(notConf.content.length)*notConf.width)){ notConf.middle.css('left',notConf.content.length*notConf.width+'px'); } notConf.middle.not(':animated').animate({left:"-="+notConf.width},600,function(){notConf.isanimate=true;}); if(notConf.mid.position().left<=(-(notConf.content.length)*notConf.width)){ notConf.mid.css('left',notConf.content.length*notConf.width+'px'); } notConf.mid.not(':animated').animate({left:"-="+notConf.width},600,function(){notConf.isanimate=true;}); //记录当前图片 if(notConf.isanimate){ notConf.isanimate=false; if(notConf.count<notConf.content.length-1){ notConf.count++ }else{ notConf.count=0; } cur_btn(); } } //右滑动 function move_right(index){ //是否点击过底部按钮 if(typeof index=='number'){ notConf.isbottom=1; notConf.middle.not(':animated').animate({left:-notConf.width*index},500); notConf.mid.not(':animated').animate({left:-notConf.width*index},500); }else{ if(notConf.isbottom){ notConf.isbottom=0; check(); } notConf.middle.not(':animated').animate({left:"+="+notConf.width},500,function(){ if(notConf.middle.position().left>=notConf.content.length*notConf.width){ notConf.middle.css('left',-notConf.content.length*notConf.width+'px'); } notConf.isanimate=true; }); notConf.mid.not(':animated').animate({left:"+="+notConf.width},500,function(){ if(notConf.mid.position().left>=notConf.content.length*notConf.width){ notConf.mid.css('left',-notConf.content.length*notConf.width+'px'); } notConf.isanimate=true; }); //记录当前图片 if(notConf.isanimate){ notConf.isanimate=false; if(notConf.count){ notConf.count--; }else{ notConf.count=notConf.content.length-1; } cur_btn(); } } } //obo判断移动方向 传参数1:left或0:right function move(obo){ if(obo){ move_left(); }else{ move_right(); } } //是否显示左右滑动按钮 if(options.isBtn){ }else{ notConf.btn_l.hide(); notConf.btn_r.hide(); } //浏览器窗口大小监测 $(window).resize(function(){ notConf.flag=1; setwindow(); //是否自动滑动 /*if(options.isAuto){ if(c) clearInterval(c); c=setInterval(function(){move();},options.speed); }*/ }); //是否自动 if(options.isAuto){ var cl=setInterval(function(){move(options.LorR);},options.speed); p_this.mouseleave(function(){ clearInterval(cl); cl=setInterval(function(){move(options.LorR);},options.speed); }).mouseenter(function(){ clearInterval(cl); }); } notConf.btn_l.bind("click",function(){move()}); notConf.btn_r.bind("click",function(){move(1)}); return this; //返回this 使方法可链 }, /** * 功能介绍:输入框 失去焦点 与 得到焦点 颜色切换 * 参数介绍: * color: 默认为#333,选填项,得到焦点时颜色 * gray: 默认为#999,选填项,失去焦点和为空时颜色 * text: 为空时替换文本,如:请输入搜索关键字 *--------------------------------------- * Update: 2014.5.20 */ 'defaultInput':function(options){ p_this=$(this); options=$.extend({ color:'#333', gray:'#999', text:'请输入搜索关键字' },options); (p_this.find('input[type=text]').length?p_this.find('input[type=text]'):p_this).each(function(index){ $(this).focus(function(){ var val=$(this).val(); $(this).css('color',options.color); if(val==options.text){ $(this).val(''); }else{ return false; } }).blur(function(){ var val=$(this).val(); if(val==''){ $(this).val(options.text); $(this).css('color',options.gray); }else{ $(this).css('color',options.color); } }); }); return this; }, /** * 功能介绍:文字若图片单向上下滑动 * 参数介绍: * ns: 默认为 3000,选填项 * auto: 默认为 true,选填项 * s: 默认为 380,选填项 *--------------------------------------- * Update: 2015.8.19 */ 'upAndDown':function(options){ p_this=$(this); //设置默认值 $.extend合并新参数 options=$.extend({ ns:3000, auto:true, s:380 },options); var notConf=$.extend({ l:p_this.find("[role='left']"), //左按钮 r:p_this.find("[role='right']"), //右按钮 v:p_this.find("[role='view']"), //可视区域 m:p_this.find("[role='move']") //可移动目标 },options); var h=notConf.m.children().height(), len=notConf.m.children().length; notConf.m.height(h*len); var cl=null,cr=null; var t=notConf.m.position().top; notConf.r.click(function(){ if(!notConf.m.is(':animated')){ t=notConf.m.position().top; if(t<0){ notConf.m.animate({top:'+='+h+'px'},notConf.s); } } }); notConf.l.click(function(){ if(!notConf.m.is(':animated')){ t=notConf.m.position().top; if(h-h*len<t){ notConf.m.animate({top:'-='+h+'px'},notConf.s); } } }); function auto_move(){ if(!notConf.m.is(':animated')){ t=notConf.m.position().top; if(h-h*len<t){ notConf.m.animate({top:'-='+h+'px'},notConf.s); }else{ notConf.m.css("top","0"); } } } if(notConf.auto){ var cl=setInterval(function(){auto_move();},notConf.ns); } p_this.hover(function(){clearInterval(cl)},function(){cl=setInterval(function(){auto_move();},notConf.ns);}); } }); //个人插件 end })(jQuery);