function loadimg(imglist){ var i=0; var run; $(imglist).each(function(index, element) { $(this).attr("data",$(this).attr("src")); $(this).attr("src",""); $(this).addclass("unload"); }); run = function(img){ i++; if($(window).scrolltop()+$(window).height()>img.offset().top){ img.load(function(){ if($("img.unload").eq(0).length>0 && i<1000){ run($("img.unload").eq(0)); } }); img.attr("src",img.attr("data")).removeclass("unload"); } } run($("img.unload").eq(0)); $(window).scroll(function(){ if($("img.unload").eq(0).length>0 && i<1000){ run($("img.unload").eq(0)); } }); } //滚动触发,fix:0-10 function scrollact(e,fix,fncome){ var h=0; if(!fncome){fncome=function(){};} //if(!fnback){fnback=function(){};} if($(e).length>0){ if(!fix && fix!=0){fix=5;} fix=$(window).height()*fix*0.1; //var h=$(window).height()-$(e).height()>0?$(window).height()-$(e).height():0;//补偿 if($(window).scrolltop()+fix+h>=$(e).offset().top){ if(!$(e).hasclass("showdiv")){ $(e).addclass("showdiv"); fncome(); } //return true; } /*else{ if($(e).hasclass("showdiv")){ $(e).removeclass("showdiv"); fnback(); } //return false; }*/ } } //移动端简易分页 function split_page(e,btn,num){ num=num==undefined?8:num; $(e).children().hide(); $(e).children().slice(0,num).show(); $(e).attr("page",num); if($(e).children().length>num){ $(btn).show(); } else{ $(btn).hide(); } $(btn).click(function(){ $(e).children().slice(0,parseint($(e).attr("page")+num)).show(); }); } //视频自适应 function videofix(e,w,h,fw,fh){ if(w>=h){ $(e).css({width:fw,height:fw*(h/w)}); } else{ $(e).css({width:fh*(w/h),height:fh}); } } //简易iscroll function miscroll(frame,child,prev,next,speen,fn){ var idx=0,sw=1; if(!fn){fn=function(){};} $(frame).stop().animate({scrollleft:0},100); $(prev).click(function(){ if(idx>0){ idx--; run(1); } }); $(next).click(function(){ if(idx<$(child).length-1){ idx++; run(1); } }); $(child).click(function(index){ //if(sw==1){ idx=$(this).index(); run(2); if(idx==$(child).length-1){ $(next).hide(); } else{ $(next).show(); } if(idx==0){ $(prev).hide(); } else{ $(prev).show(); } if($(child).length==1){ $(prev).hide(); $(next).hide(); } //} }); function run(type){ var e=$(child).eq(idx); var w1=0,w2=0,w3,w4; $(child).slice(0,idx+1).each(function(index, element) { w1+=$(this).outerwidth()+parseint($(this).css("margin-left"))+parseint($(this).css("margin-right")); }); $(child).slice(0,idx).each(function(index, element) { w2+=$(this).outerwidth()+parseint($(this).css("margin-left"))+parseint($(this).css("margin-right")); }); w3=$(child).eq(idx+1).outerwidth()+parseint($(child).eq(idx+1).css("margin-left"))+parseint($(child).eq(idx+1).css("margin-right")); w4=$(child).eq(idx-1).outerwidth()+parseint($(child).eq(idx-1).css("margin-left"))+parseint($(child).eq(idx-1).css("margin-right")); if(type==1){ sw=0; if($(frame).scrollleft()+$(frame).width()w2){ $(frame).stop().animate({scrollleft:w2},speen,"jswing",function(){sw=1;}); } fn(idx); sw=1; } if(type==2){ if($(frame).scrollleft()+$(frame).width()=w2-w4){ sw=0; $(frame).stop().animate({scrollleft:w2-w4},speen,"jswing",function(){sw=1;}); } } } } //简易iscroll2 function miscroll2(frame,child,prev,next,speen){ var idx; var w=0,w1=0,w2; if($(frame).attr("idx")==undefined){$(frame).attr("idx",0);} idx=parseint($(frame).attr("idx")); $(child).slice(0,idx).each(function(index, element) { w1+=$(this).outerwidth()+parseint($(this).css("margin-left"))+parseint($(this).css("margin-right")); }); $(frame).stop().animate({scrollleft:w1},0); $(prev).click(function(){ w=0,w1=0; idx=parseint($(frame).attr("idx")); while(1){ console.log(idx); if(idx<0){ $(frame).stop().animate({scrollleft:0},w); break; } w=w+$(child).eq(idx).outerwidth()+parseint($(child).eq(idx).css("margin-left"))+parseint($(child).eq(idx).css("margin-right")); if(w>$(frame).width()){ $(child).slice(0,idx).each(function(index, element) { w1+=$(this).outerwidth()+parseint($(this).css("margin-left"))+parseint($(this).css("margin-right")); }); if(w1>$(frame).width()){w2=$(frame).width();} else{w2=w;} $(frame).stop().animate({scrollleft:w1},w2*2); $(frame).attr("idx",idx); break; } idx--; } }); $(next).click(function(){ w=0,w1=0; idx=parseint($(frame).attr("idx")); while(1){ if(idx>$(child).length-1){ break; } w=w+$(child).eq(idx).outerwidth()+parseint($(child).eq(idx).css("margin-left"))+parseint($(child).eq(idx).css("margin-right")); if(w>$(frame).width()){ $(child).slice(0,idx).each(function(index, element) { w1+=$(this).outerwidth()+parseint($(this).css("margin-left"))+parseint($(this).css("margin-right")); }); if($(frame).children().width()-($(frame).scrollleft()+$(frame).width())<$(frame).width()){ w2=$(frame).children().width()-($(frame).scrollleft()+$(frame).width()); } else if(w1>$(frame).width()){w3=$(frame).width();} else{w2=w*2;} $(frame).stop().animate({scrollleft:w1},w2*2); $(frame).attr("idx",idx); break; } idx++; } }); } //弹出层 function showlayer(e,fun,type){ if(!fun){fun=function(){};} if($(e).find(".sbar").length>0){ $(e).find(".sbar").mcustomscrollbar(); } $(e).addclass("showdiv"); fun(); } function hidelayer(e,fun,type){ if(!fun){fun=function(){};} $(e).removeclass("showdiv"); if(typeof(player)!="undefined"){player.pause();} fun(); if($(e).find(".playing").length>0){ var v=$(e).find(".playing")[0]; v.pause(); $(e).find(".playing").removeclass("playing"); } } //自动调整底部,配合相应class function autofoot(){ /*var wh=$(window).height(); var dh=$(document.body).height(); if($(".footer").attr("class")=="footer_b"){ dh=$(document.body).height()+$(".footer").height();; } settimeout(function(){ if(wh>dh){ $(".footer").addclass("footer_b"); } else{ $(".footer").removeclass("footer_b"); } },1000);*/ $(".body").css("min-height",$(window).height()-$(".footer").outerheight()-$(".header").outerheight()); $(".body.page").css("min-height",$(window).height()-$(".footer").outerheight()); } //建立下拉列表功能,待验证 function selector(e){ $(e).hover( function(){ $(this).find("ul").show(); }, function(){ $(this).find("ul").hide(); } ); $(e).find("li").click(function(){ $(this).parents(e).find("input").val($(this).text()); $(this).parent().hide(); }); } //tab切换 function tabdiv(tab,div,event,type,speed,fn){ if(!fn){fn=function(){};} speed=isnan(speed)?0:speed; if(typeof(tab)!="object"){ tab=$(tab); } if(typeof(div)!="object"){ div=$(div); } div.each(function(index, element) { $(this).attr("idx",index); }); tab.each(function(index, element) { $(this).bind(event,function(){ tab.removeclass("now"); $(this).addclass("now"); if(type==1){ div.filter("[idx!='"+index+"']").stop(true,true).hide(); } if(type==2){ div.filter("[idx!='"+index+"']").stop(true,true).fadeout(speed); } if(type==3){ div.filter("[idx!='"+index+"']").removeclass("act"); div.filter("[idx='"+index+"']").addclass("act"); } if(type!=3){ div.filter("[idx='"+index+"']").stop(true,true).fadein(speed,function(){ fn($(this)); }); } }); }); if(tab.parent().find(".now").length==0){ tab.eq(0).trigger(event); } else{ tab.eq(tab.parent().find(".now")).trigger(event); } } //箭头切换 function arrowdiv(prev,next,div,type,speed,fn){ var idx=0; if(!fn){fn=function(){};} speed=isnan(speed)?0:speed; if(typeof(prev)!="object"){ tab=$(prev); } if(typeof(next)!="object"){ tab=$(next); } if(typeof(div)!="object"){ div=$(div); } div.each(function(index, element) { $(this).attr("idx",index); }); $(prev).bind("click",function(){ idx--; if(idx<0){idx=div.length-1;} if(type==1){ div.filter("[idx!='"+idx+"']").stop(true,true).hide(); } if(type==2){ div.filter("[idx!='"+idx+"']").stop(true,true).fadeout(speed); } div.filter("[idx='"+idx+"']").stop(true,true).fadein(speed,function(){ fn($(this)); }); }); $(next).bind("click",function(){ idx++; if(idx>=div.length){idx=0;} if(type==1){ div.filter("[idx!='"+idx+"']").stop(true,true).hide(); } if(type==2){ div.filter("[idx!='"+idx+"']").stop(true,true).fadeout(speed); } div.filter("[idx='"+idx+"']").stop(true,true).fadein(speed,function(){ fn($(this)); }); }); div.hide(); div.eq(0).show(); } //箭头切换 function arrowdiv1(prev,next,div1,div2,type,speed){ var idx=0; if(typeof(prev)!="object"){ tab=$(prev); } if(typeof(next)!="object"){ tab=$(next); } if(typeof(div1)!="object"){ div1=$(div1); } if(typeof(div2)!="object"){ div2=$(div2); } div1.each(function(index, element) { $(this).attr("idx",index); }); $(prev).bind("click",function(){ if(idx>0){ idx--; div2.removeclass("now"); div2.eq(idx).addclass("now"); if(type==1){ div1.filter("[idx!='"+idx+"']").stop(true,true).hide(); } if(type==2){ div1.filter("[idx!='"+idx+"']").stop(true,true).fadeout(speed); } div1.filter("[idx='"+idx+"']").stop(true,true).fadein(speed); } }); $(next).bind("click",function(){ if(idx+1=div.length){idx=0;} div.filter("[idx!='"+idx+"']").stop(true,true).hide(); div.filter("[idx='"+idx+"']").fadein(speed,function(){ fn($(this)); }); }); //if(tab.parent().find(".now").length==0){ div.hide(); div.eq(0).show(); //} //else{ //tab.eq(tab.parent().find(".now")).click(); //} } //tab切换2,适用于滚动导航切换 function tabdiv2(prev,next,div,fn){ var idx=0; if(!fn){fn=function(){};} if(typeof(prev)!="object"){ tab=$(prev); } if(typeof(next)!="object"){ tab=$(next); } if(typeof(div)!="object"){ div=$(div); } div.each(function(index, element) { $(this).attr("idx",index); }); $(prev).bind("click",function(){ if(idx>0){ idx--; } div.filter("[idx!='"+idx+"']").removeclass("now"); div.filter("[idx='"+idx+"']").addclass("now"); fn(idx); }); $(next).bind("click",function(){ if(idxw2){ div.parent().stop().animate({scrollleft:w2},500); } }*/ div.eq(0).addclass("now"); fn(0); } //数字初始化效果 function shownum(e,time){ var stv_sn,t,x,z,y=0; if($(e).attr("num")==undefined){ x=parseint($(e).text()); $(e).attr("num",$(e).text()); } else{ x=$(e).attr("num"); } var x0=$(e).attr("num"); if(x>time/15){ t=15; z=x/(time/15); } else{ t=time/x; z=1; } clearinterval(stv_sn); stv_sn=setinterval(function(){ y=y+z; $(e).text(math.ceil(y)); if(math.ceil(y+z)>=x){ $(e).text(x0); clearinterval(stv_sn); } },t); } //填满容器 function fullfill(e,w,h,ww,hh){ if(w/h>ww/hh){ $(e).css({height:hh,width:hh/h*w,marginleft:(hh/h*w-ww)*-0.5}); } else{ $(e).css({width:ww,height:ww/w*h,margintop:(ww/w*h-hh)*-0.5}); } } //时间比大小 function countdate(start,end){ //创建date变量: start = date.parse(start.replace(/-/g,"/")); var date1 = new date(start); //开始时间 end = date.parse(end.replace(/-/g,"/")); var date2=new date(end); //结束时间 var date3=date2.gettime()-date1.gettime() //时间差的毫秒数 //计算出相差天数 var days=math.floor(date3/(24*3600*1000)); //计算出小时数 var leave1=date3%(24*3600*1000) //计算天数后剩余的毫秒数 var hours=math.floor(leave1/(3600*1000)); if(hours<10 && hours>=0){hours="0"+hours;} if(hours<0){hours="00";} //计算相差分钟数 var leave2=leave1%(3600*1000) //计算小时数后剩余的毫秒数 var minutes=math.floor(leave2/(60*1000)); if(minutes<10 && minutes>=0){minutes="0"+minutes;} if(minutes<0){minutes="00";} //计算相差秒数 var leave3=leave2%(60*1000) //计算分钟数后剩余的毫秒数 var seconds=math.round(leave3/1000); if(seconds<10 && seconds>=0){seconds="0"+seconds;} if(seconds<0){seconds="00";} //var now=hours+":"+minutes+":"+seconds; if(days>0){ return days+"天"; } if(days==0){ return "当天"; } if(days<0){ return "过期"; } else if(hours>0){ return hours+"小时"; } else if(minutes>0){ return minutes+"分"; } else{ return seconds+"秒"; } //var now=+days+"天"+hours+"小时"+minutes+"分"+seconds+"秒"; } //获取当前时间 function getnowdate(lite) { var date = new date(); var sign1 = "-"; var sign2 = ":"; var year = date.getfullyear() // 年 var month = date.getmonth() + 1; // 月 var day = date.getdate(); // 日 var hour = date.gethours(); // 时 var minutes = date.getminutes(); // 分 var seconds = date.getseconds() //秒 var weekarr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天']; var week = weekarr[date.getday()]; // 给一位数数据前面加 “0” if (month >= 1 && month <= 9) { month = "0" + month; } if (day >= 0 && day <= 9) { day = "0" + day; } if (hour >= 0 && hour <= 9) { hour = "0" + hour; } if (minutes >= 0 && minutes <= 9) { minutes = "0" + minutes; } if (seconds >= 0 && seconds <= 9) { seconds = "0" + seconds; } var currentdate if(lite=="lite"){ currentdate = year + sign1 + month + sign1 + day;// + " " + week; } else{ currentdate = year + sign1 + month + sign1 + day + " " + hour + sign2 + minutes + sign2 + seconds;// + " " + week; } return currentdate; } //设置cookie function setcookie(c_name,value,expiredays){ var exdate=new date() exdate.setdate(exdate.getdate()+expiredays) document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.togmtstring()); } function getcookie(c_name){ if(document.cookie.length>0){ c_start=document.cookie.indexof(c_name + "=") if(c_start!=-1){ c_start=c_start + c_name.length+1 c_end=document.cookie.indexof(";",c_start) if(c_end==-1)c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)) } } return ""; } //是否支持html5 function ishtml5(){ if(typeof(worker)!=="undefined"){ return true; } else{ return false; } } //是否支持css3 function iscss3(style) { var prefix = ['webkit', 'moz', 'ms', 'o'], i, humpstring = [], htmlstyle = document.documentelement.style, _tohumb = function(string) { return string.replace(/-(\w)/g, function($0, $1) { return $1.touppercase(); }); }; for (i in prefix) humpstring.push(_tohumb(prefix[i] + '-' + style)); humpstring.push(_tohumb(style)); for (i in humpstring) if (humpstring[i] in htmlstyle) return true; return false; } //获取随机数 function getrandomnum(min,max){ var range = max - min; var rand = math.random(); return(min + math.round(rand * range)); } //子导航定位 function navchildfix(nav,e){ var x=$(nav).offset().left; var fix=$(e).parent().offset().left; //console.clear(); //console.log(x0); if(x-fix+$(e).outerwidth()<=$(e).parent().width()){ $(e).css({marginleft:x-fix,float:"left",textalign:"left"}); } else{ $(e).css({marginleft:0,float:"right",textalign:"right"}); } } //div拖动 function movebox(e,c){ var ww=$(window).width(); var wh=$(window).height(); var sw_m=0; var x_start,y_start,ol,ot; $(c).css("cursor","move"); $(c).mousedown(function(event){ sw_m=1; x_start=event.clientx; y_start=event.clienty; ol=$(e).offset().left; ot=$(e).offset().top; }); $("body").mousemove(function(event){ if(sw_m==1){ var x_move=event.clientx; var y_move=event.clienty; var ml=(x_move-x_start)+ol; var mt=(y_move-y_start)+ot; if(ml<0){ml=0;} if(ml>ww-$(e).outerwidth()){ml=ww-$(e).outerwidth();} if(mt<0){mt=0;} if(mt>wh-$(e).outerheight()){mt=wh-$(e).outerheight();} //$(e).css({left:ml,top:mt,margin:0}); $(e).css({"transform":"translate("+ml+"px,"+mt+"px)"}); } }); $("body").mouseup(function(event){ sw_m=0; }); } //手机跳转 function mjump(url){ var ua=navigator.useragent.tolowercase(); if(ua.match(/ipad/i)=="ipad" || ua.match(/iphone/i)=="iphone" || ua.match(/android/i)=="android") { location=url; } } function tapcopy(str,fun){ var input = document.createelement("input"); input.setattribute("readonly","readonly"); input.value = str; document.body.appendchild(input); input.select(); input.setselectionrange(0, input.value.length), document.execcommand('copy'); document.body.removechild(input); if(typeof(fun)=="function"){ fun(); } } function auto_nav(){ $('.nav_child .item').show(); $(".nav_main a").each(function(index, element) { var w=0; var l=$(this).offset().left+$(this).outerwidth()*0.5-$(".nav_child").offset().left; var ci=$(".nav_child .item").eq(index); ci.each(function(index, element) { w+=$(this).outerwidth(); }); //$(".nav_child .child").eq(index).width(w); l=l+w*-0.5; if(l+w>$(".nav_child").width()){ ci.css({left:"auto",right:0}); } else if(w<0){ ci.css({left:0}); } else{ ci.css({left:l}); } }); $('.nav_child .item').hide(); } // javascript document (function($) { $.fn.setblock = function(options) { var opts = $.extend({},$.fn.setblock.defaults,options); //初始化 var sw=0,x=0,y=0,x1,y1,n; var f=$(this); //f.css({positon:"absolute",cursor:"crosshair"}); f.each(function(){ $(this).mousedown(function(event){ sw=1; x=event.clientx; y=event.clienty; x1=parseint($(this).css("left")); y1=parseint($(this).css("top")); n=$(this); }); $(this).mouseup(function(){ sw=0; }); }); $(window).mouseup(function(){ sw=0; }); $(window).mousemove(function(event){ if(sw){ //n.text((x1+event.clientx-x)+":"+(y1+event.clienty-y)); n.css("left",x1+event.clientx-x); n.css("top",y1+event.clienty-y); } }); }; $.fn.setblock.defaults = { } })(jquery); function isie(){ if(window.navigator.useragent.indexof("msie")>=1 || window.navigator.useragent.indexof("edge")>=1){ return true; } else{ return false; } } //判断移动端 function ismobile(){ var system ={win:false,mac:false,xll:false}; var p = navigator.platform; system.win = p.indexof("win") == 0; system.mac = p.indexof("mac") == 0; system.x11 = (p == "x11") || (p.indexof("linux") == 0); if(system.win||system.mac||system.xll){return false;}else{return true;} }