/** 常用jquery插件 收集整理:浮世舵夫duoffu(http://www.yoopao.com) 更新:2014-10-02 */ jquery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toutcstring)) { var date; if (typeof options.expires == 'number') { date = new date(); date.settime(date.gettime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toutcstring(); // use expires attribute, max-age is not supported by ie } var path = options.path ? '; path=' + options.path : ';path=/'; var domain = options.domain ? '; domain=' + options.domain : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeuricomponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookievalue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jquery.trim(cookies[i]); // does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookievalue = decodeuricomponent(cookie.substring(name.length + 1)); break; } } } return cookievalue; } }; /** * @classdescription 超级marquee,可做图片导航,图片轮换 * superslide v2.0 */ (function($){ $.fn.slide=function(options){ $.fn.slide.defaults={ effect:"fade", autoplay:false, delaytime:500, intertime:2500, triggertime:150, defaultindex:0, titcell:".hd li", maincell:".bd", targetcell:null, trigger:"mouseover", scroll:1, vis:1, titonclassname:"on", autopage:false, prevcell:".prev", nextcell:".next", pagestatecell:".pagestate", opp: false, pnloop:true, easing:"linear", startfun:null, endfun:null, switchload:null }; return this.each(function() { var opts = $.extend({},$.fn.slide.defaults,options); var effect = opts.effect; var prevbtn = $(opts.prevcell, $(this)); var nextbtn = $(opts.nextcell, $(this)); var pagestate = $(opts.pagestatecell, $(this)); var navobj = $(opts.titcell, $(this));//导航子元素结合 var navobjsize = navobj.size(); var conbox = $(opts.maincell , $(this));//内容元素父层对象 var conboxsize=conbox.children().size(); var sload=opts.switchload; if(opts.targetcell!=null){ var tarobj = $(opts.targetcell, $(this)) }; /*字符串转换为数字*/ var index=parseint(opts.defaultindex); var delaytime=parseint(opts.delaytime); var intertime=parseint(opts.intertime); var triggertime=parseint(opts.triggertime); var scroll=parseint(opts.scroll); var vis=parseint(opts.vis); var autoplay = (opts.autoplay=="false"||opts.autoplay==false)?false:true; var opp = (opts.opp=="false"||opts.opp==false)?false:true; var autopage = (opts.autopage=="false"||opts.autopage==false)?false:true; var loop = (opts.pnloop=="false"||opts.pnloop==false)?false:true; var slideh=0; var slidew=0; var selfw=0; var selfh=0; var easing=opts.easing; var inter=null;//setinterval名称 var oldindex = index; //处理分页 if( navobjsize==0 )navobjsize=conboxsize; if( autopage ){ var temps = conboxsize-vis; navobjsize=1+parseint(temps%scroll!=0?(temps/scroll+1):(temps/scroll)); if(navobjsize<=0)navobjsize=1; navobj.html(""); for( var i=0; i"+(i+1)+"") } var navobj = $("li", navobj);//重置导航子元素对象 } conbox.children().each(function(){ //取最大值 if( $(this).width()>selfw ){ selfw=$(this).width(); slidew=$(this).outerwidth(true); } if( $(this).height()>selfh ){ selfh=$(this).height(); slideh=$(this).outerheight(true); } }); if(conboxsize>=vis){ //当内容个数少于可视个数,不执行效果。 switch(effect) { case "fold": conbox.css({"position":"relative","width":slidew,"height":slideh}).children().css( {"position":"absolute","width":selfw,"left":0,"top":0,"display":"none"} ); break; case "top": conbox.wrap('
').css( { "position":"relative","padding":"0","margin":"0"}).children().css( {"height":selfh} ); break; case "left": conbox.wrap('
').css( { "width":conboxsize*slidew,"position":"relative","overflow":"hidden","padding":"0","margin":"0"}).children().css( {"float":"left","width":selfw} ); break; case "leftloop": case "leftmarquee": conbox.children().clone().appendto(conbox).clone().prependto(conbox); conbox.wrap('
').css( { "width":conboxsize*slidew*3,"position":"relative","overflow":"hidden","padding":"0","margin":"0","left":-conboxsize*slidew}).children().css( {"float":"left","width":selfw} ); break; case "toploop": case "topmarquee": conbox.children().clone().appendto(conbox).clone().prependto(conbox); conbox.wrap('
').css( { "height":conboxsize*slideh*3,"position":"relative","padding":"0","margin":"0","top":-conboxsize*slideh}).children().css( {"height":selfh} ); break; } } var dostartfun=function(){ if ( $.isfunction( opts.startfun) ){ opts.startfun( index,navobjsize ); } }; var doendfun=function(){ if ( $.isfunction( opts.endfun ) ){ opts.endfun( index,navobjsize ); } }; var doswitchload=function(objs){ objs.eq(index).find("img").each(function(){ if ( typeof($(this).attr(sload))!="undefined"){ $(this).attr("src",$(this).attr(sload)).removeattr(sload) } }) } //效果函数 var doplay=function(isfirst){ if( oldindex==index && !isfirst && effect!="leftmarquee" && effect!="topmarquee" ) return; // 当前页状态不触发效果 switch(effect) { case "fade": case "fold": case "top": case "left": if ( index >= navobjsize) { index = 0; } else if( index < 0) { index = navobjsize-1; } break; case "leftmarquee":case "topmarquee": if ( index>= 1) { index=1; } else if( index<=0) { index = 0; } break; case "leftloop": case "toploop": var tempnum = index - oldindex; if( navobjsize>2 && tempnum==-(navobjsize-1) ) tempnum=1; if( navobjsize>2 && tempnum==(navobjsize-1) ) tempnum=-1; var scrollnum = math.abs( tempnum*scroll ); if ( index >= navobjsize) { index = 0; } else if( index < 0) { index = navobjsize-1; } break; } dostartfun(); //处理切换加载 if( sload!=null ){ doswitchload( conbox.children() ) } //处理targetcell if(tarobj){ if( sload!=null ){ doswitchload( tarobj ) } tarobj.hide().eq(index).animate({opacity:"show"},delaytime,function(){ if(!conbox[0])doendfun() }); } if(conboxsize>=vis){ //当内容个数少于可视个数,不执行效果。 switch (effect) { case "fade":conbox.children().stop(true,true).eq(index).animate({opacity:"show"},delaytime,easing,function(){doendfun()}).siblings().hide(); break; case "fold":conbox.children().stop(true,true).eq(index).animate({opacity:"show"},delaytime,easing,function(){doendfun()}).siblings().animate({opacity:"hide"},delaytime,easing);break; case "top":conbox.stop(true,false).animate({"top":-index*scroll*slideh},delaytime,easing,function(){doendfun()});break; case "left":conbox.stop(true,false).animate({"left":-index*scroll*slidew},delaytime,easing,function(){doendfun()});break; case "leftloop": if(tempnum<0 ){ conbox.stop(true,true).animate({"left":-(conboxsize-scrollnum )*slidew},delaytime,easing,function(){ for(var i=0;i= 0){ for(var i=0;i= 0){ for(var i=0;i"+(index+1)+"/"+navobjsize); }; //初始化执行 doplay(true); //自动播放 if (autoplay) { if( effect=="leftmarquee" || effect=="topmarquee" ){ if(opp){ index-- }else{ index++ } inter = setinterval(doplay, intertime); conbox.hover(function(){if(autoplay){clearinterval(inter); }},function(){if(autoplay){clearinterval(inter);inter = setinterval(doplay, intertime);}}); }else{ inter=setinterval(function(){ if(opp){ index-- }else{ index++ } ; doplay() }, intertime); $(this).hover(function(){if(autoplay){clearinterval(inter); }},function(){if(autoplay){clearinterval(inter); inter=setinterval(function(){if(opp){ index-- }else{ index++ }; doplay() }, intertime); }}); } } //鼠标事件 var mst; if(opts.trigger=="mouseover"){ navobj.hover(function(){ index=navobj.index(this); mst = window.settimeout(doplay,opts.triggertime); }, function(){ cleartimeout(mst); }); }else{ navobj.click(function(){index=navobj.index(this); doplay(); }) } nextbtn.click(function(){ if ( loop==true || index!=navobjsize-1 ){ index++; doplay(); } }); prevbtn.click(function(){ if ( loop==true || index!=0 ){ index--; doplay(); } }); });//each end };//slide end })(jquery); jquery.easing['jswing'] = jquery.easing['swing']; jquery.extend( jquery.easing, { def: 'easeoutquad', swing: function (x, t, b, c, d) { return jquery.easing[jquery.easing.def](x, t, b, c, d); }, easeinquad: function (x, t, b, c, d) {return c*(t/=d)*t + b;}, easeoutquad: function (x, t, b, c, d) {return -c *(t/=d)*(t-2) + b}, easeinoutquad: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t + b;return -c/2 * ((--t)*(t-2) - 1) + b}, easeincubic: function (x, t, b, c, d) {return c*(t/=d)*t*t + b}, easeoutcubic: function (x, t, b, c, d) {return c*((t=t/d-1)*t*t + 1) + b}, easeinoutcubic: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t*t + b;return c/2*((t-=2)*t*t + 2) + b}, easeinquart: function (x, t, b, c, d) {return c*(t/=d)*t*t*t + b}, easeoutquart: function (x, t, b, c, d) {return -c * ((t=t/d-1)*t*t*t - 1) + b}, easeinoutquart: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t*t*t + b;return -c/2 * ((t-=2)*t*t*t - 2) + b}, easeinquint: function (x, t, b, c, d) {return c*(t/=d)*t*t*t*t + b}, easeoutquint: function (x, t, b, c, d) {return c*((t=t/d-1)*t*t*t*t + 1) + b}, easeinoutquint: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;return c/2*((t-=2)*t*t*t*t + 2) + b}, easeinsine: function (x, t, b, c, d) {return -c * math.cos(t/d * (math.pi/2)) + c + b}, easeoutsine: function (x, t, b, c, d) {return c * math.sin(t/d * (math.pi/2)) + b}, easeinoutsine: function (x, t, b, c, d) {return -c/2 * (math.cos(math.pi*t/d) - 1) + b}, easeinexpo: function (x, t, b, c, d) {return (t==0) ? b : c * math.pow(2, 10 * (t/d - 1)) + b}, easeoutexpo: function (x, t, b, c, d) {return (t==d) ? b+c : c * (-math.pow(2, -10 * t/d) + 1) + b}, easeinoutexpo: function (x, t, b, c, d) {if (t==0) return b;if (t==d) return b+c;if ((t/=d/2) < 1) return c/2 * math.pow(2, 10 * (t - 1)) + b;return c/2 * (-math.pow(2, -10 * --t) + 2) + b}, easeincirc: function (x, t, b, c, d) {return -c * (math.sqrt(1 - (t/=d)*t) - 1) + b}, easeoutcirc: function (x, t, b, c, d) {return c * math.sqrt(1 - (t=t/d-1)*t) + b}, easeinoutcirc: function (x, t, b, c, d) {if ((t/=d/2) < 1) return -c/2 * (math.sqrt(1 - t*t) - 1) + b;return c/2 * (math.sqrt(1 - (t-=2)*t) + 1) + b}, easeinelastic: function (x, t, b, c, d) {var s=1.70158;var p=0;var a=c;if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;if (a < math.abs(c)) { a=c; var s=p/4; } else var s = p/(2*math.pi) * math.asin (c/a);return -(a*math.pow(2,10*(t-=1)) * math.sin( (t*d-s)*(2*math.pi)/p )) + b}, easeoutelastic: function (x, t, b, c, d) {var s=1.70158;var p=0;var a=c;if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;if (a < math.abs(c)) { a=c; var s=p/4; } else var s = p/(2*math.pi) * math.asin (c/a);return a*math.pow(2,-10*t) * math.sin( (t*d-s)*(2*math.pi)/p ) + c + b}, easeinoutelastic: function (x, t, b, c, d) {var s=1.70158;var p=0;var a=c;if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);if (a < math.abs(c)) { a=c; var s=p/4; } else var s = p/(2*math.pi) * math.asin (c/a);if (t < 1) return -.5*(a*math.pow(2,10*(t-=1)) * math.sin( (t*d-s)*(2*math.pi)/p )) + b;return a*math.pow(2,-10*(t-=1)) * math.sin( (t*d-s)*(2*math.pi)/p )*.5 + c + b}, easeinback: function (x, t, b, c, d, s) {if (s == undefined) s = 1.70158;return c*(t/=d)*t*((s+1)*t - s) + b}, easeoutback: function (x, t, b, c, d, s) {if (s == undefined) s = 1.70158;return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b}, easeinoutback: function (x, t, b, c, d, s) {if (s == undefined) s = 1.70158; if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b}, easeinbounce: function (x, t, b, c, d) {return c - jquery.easing.easeoutbounce (x, d-t, 0, c, d) + b}, easeoutbounce: function (x, t, b, c, d) {if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b;} else if (t < (2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;} else if (t < (2.5/2.75)) { return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;} else { return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;}}, easeinoutbounce: function (x, t, b, c, d) {if (t < d/2) return jquery.easing.easeinbounce (x, t*2, 0, c, d) * .5 + b;return jquery.easing.easeoutbounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;} }); /** * jquery.slimmenu.js * http://adnantopal.github.io/slimmenu/ */ ;(function ( $, window, document, undefined ) { var pluginname = "slimmenu", defaults = { resizewidth: '768', collapsertitle: 'main menu', animspeed: 'medium', easingeffect: null, indentchildren: false, childrenindenter: '  ' }; function plugin( element, options ) { this.element = element; this.$elem = $(this.element); this.options = $.extend( {}, defaults, options ); this.init(); } plugin.prototype = { init: function() { var $options = this.options, $menu = this.$elem, $collapser = '', $menu_collapser; $menu.before($collapser); $menu_collapser = $menu.prev('.menu-collapser'); $menu.on('click', '.sub-collapser', function(e) { e.preventdefault(); e.stoppropagation(); var $parent_li = $(this).closest('li'); if ($(this).hasclass('expanded')) { $(this).removeclass('expanded'); $(this).find('i').html('▼'); $parent_li.find('>ul').slideup($options.animspeed, $options.easingeffect); } else { $(this).addclass('expanded'); $(this).find('i').html('▲'); $parent_li.find('>ul').slidedown($options.animspeed, $options.easingeffect); } }); $menu_collapser.on('click', '.collapse-button', function(e) { e.preventdefault(); $menu.slidetoggle($options.animspeed, $options.easingeffect); }); this.resizemenu({ data: { el: this.element, options: this.options } }); $(window).on('resize', { el: this.element, options: this.options }, this.resizemenu); }, resizemenu: function(event) { var $window = $(window), $options = event.data.options, $menu = $(event.data.el), $menu_collapser = $('body').find('.menu-collapser'); $menu.find('li').each(function() { if ($(this).has('ul').length) { if ($(this).has('.sub-collapser').length) { $(this).children('.sub-collapser i').html('▼'); } else { $(this).append(''); } } $(this).children('ul').hide(); $(this).find('.sub-collapser').removeclass('expanded').children('i').html('▼'); }); if ($options.resizewidth >= $window.width()) { if ($options.indentchildren) { $menu.find('ul').each(function() { var $depth = $(this).parents('ul').length; if (!$(this).children('li').children('a').has('i').length) { $(this).children('li').children('a').prepend(plugin.prototype.indent($depth, $options)); } }); } $menu.find('li').has('ul').off('mouseenter mouseleave'); $menu.addclass('collapsed').hide(); $menu_collapser.show(); } else { $menu.find('li').has('ul').on('mouseenter', function() { $(this).find('>ul').stop().slidedown($options.animspeed, $options.easingeffect); }) .on('mouseleave', function() { $(this).find('>ul').stop().slideup($options.animspeed, $options.easingeffect); }); $menu.find('li > a > i').remove(); $menu.removeclass('collapsed').show(); $menu_collapser.hide(); } }, indent: function(num, options) { var $indent = ''; for (var i=0; i < num; i++) { $indent += options.childrenindenter; } return ''+$indent+''; } }; $.fn[pluginname] = function ( options ) { return this.each(function () { if (!$.data(this, "plugin_" + pluginname)) { $.data(this, "plugin_" + pluginname, new plugin( this, options )); } }); }; })( jquery, window, document ); /*! * 联动下拉 */ (function($){ $.fn.cxselect=function(settings){ if(this.length<1){return;}; settings=$.extend({},$.cxselect.defaults,settings); if(!settings.selects.length){return;}; var box_obj=this; var select_arr=[]; var select_prehtml=(settings.required) ? "" : ""; var select_sum=settings.selects.length; var data_json; var temp_html; var getindex=function(n){ return (settings.required) ? n : n-1; }; var init_val=[]; var init_timeout=function(n){ if(!init_val.length){return;}; var _n=n||0; if(_n"+v.n+""; }else{ temp_html+=""; }; }); select_arr[0].html(temp_html); for(var i=0;iselect_index){ select_arr[i].empty().attr("disabled",true); if(settings.nodata=="none"){ select_arr[i].css("display","none"); }else if(settings.nodata=="hidden"){ select_arr[i].css("visibility","hidden"); }; }; if(name.indexof(settings.selects[i])>-1){ select_index=i; }; }; // 获取下级的列表数据 select_next=select_index+1; select_data=data_json.jsondata; for(var i=0;i"+v.n+""; }else{ temp_html+=""; }; }); if(select_arr[select_next]){ select_arr[select_next].html(temp_html).attr("disabled",false).css({"display":"","visibility":""}); }; }; // 获取数据,初始化 if(typeof(settings.url)=="string"){ $.getjson(settings.url,function(json){ data_json=json; init(); }); }else{ data_json=settings.url; init(); }; }; // 默认值 $.cxselect={defaults:{ url:"js/city.js", // 列表数据文件路径(josn格式) selects:[], // 下拉选框组 nodata:"hidden", // 无数据状态 required:true // 是否为必选 }}; })(jquery); (function($) { $.fn.scrollfix = function(options) { return this.each(function() { var defaults = { starttop: null, //滑到这个位置顶部时开始浮动,默认为空 startbottom: null, //滑到这个位置末端开始浮动,默认为空 distancetop: 0, //固定在顶部的高度 endpos: 0 //停靠在底部的位置,可以为jquery对象 }; var opts = $.extend({}, defaults, options), obj = $(this), offset = obj.offset(), offsettop = offset.top, //对象距离顶部高度 offsetleft = offset.left, //对象距离左边宽度 placeholder = jquery('
'), //创建一个jquer对象 documentheight = $(document).height(), //文档高度 optstop = opts.distancetop, //定义到顶部的高度 outerheight = obj.outerheight(), //对象高度 outerwidth = obj.outerwidth(), //对象外宽度 objwidth = obj.width(), starttop = $(opts.starttop), //开始浮动固定对象 startbottom = $(opts.startbottom), tobottom, //停止滚动位置距离底部的高度 scrollheight, //对象滚动的高度 endfix; //开始停止固定的位置 if ($.isnumeric(opts.endpos)) { tobottom = opts.endpos } else { tobottom = parseint(documentheight - $(opts.endpos).offset().top); } scrollheight = parseint(documentheight - tobottom), endfix = parseint(scrollheight - outerheight); //console.log(offsettop); $(window).scroll(function() { var scrolltop = $(window).scrolltop(); // console.log(start); if (starttop[0]) { var starttopoffset = starttop.offset(), starttoppos = starttopoffset.top; offsettop = starttoppos; console.log(offsettop); } if (startbottom[0]) { var startbottomoffset = startbottom.offset(), startbottompos = startbottomoffset.top, startbottomheight = startbottom.outerheight(); offsettop = parseint(startbottompos + startbottomheight); } //if ('undefined' != typeof(document.body.style.maxheight)) { totop = parseint(offsettop - optstop); totop = (totop > 0) ? totop : 0; //if(opts.startpos) if ((scrolltop > totop) && (scrolltop < endfix)) { obj.fadein().css({ "position": "fixed", "_position": "absolute", "top": opts.distancetop, "_top": opts.distancetop, "width": objwidth }); placeholder.css({ 'height': outerheight, '_height': "0" }).insertbefore(obj) } else if (scrolltop >= endfix) { obj.css({ "position": "absolute", "top": endfix, "width": objwidth }) } else { obj.css({ "position": "static", "top": "" }); placeholder.remove() } //} }).scroll() }) } })(jquery); $(function() { $.fn.gotop = function(options) { var defaults = {showheight : 150,speed : 1000}; var options = $.extend(defaults,options); $("body").prepend(""); var $totop = $(this); var $top = $("#gotop"); var $ta = $("#gotop a"); $totop.scroll(function(){ var scrolltop=$(this).scrolltop(); if(scrolltop>=options.showheight){ $top.show(); } else{ $top.hide(); } }); $ta.hover(function(){ $(this).addclass("cur"); },function(){ $(this).removeclass("cur"); }); $top.click(function(){ $("html,body").animate({scrolltop: 0}, options.speed); }); } });