//rem计算
function htmlsize(psdwidth){
var ww=$(window).width();
var maxw=4096;
var minw=320;
if($(window).width()>maxw){ww=maxw;}
else if($(window).width()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("showd")){
$(e).addclass("showd");
fncome();
}
//return true;
}
/*else{
if($(e).hasclass("showd")){
$(e).removeclass("showd");
fnback();
}
//return false;
}*/
}
}
//滚动加载更多
function loadmore(e,fix,fn){
if(!fix){fix=0;}
fix=$(window).height()*fix;
$(window).scroll(function(){
if($(window).scrolltop()+$(window).height()+fix>=$(e).offset().top+$(e).outerheight()){
fn();
}
});
}
//弹出层
function showlayer(e,fun){
if(!fun){fun=function(){};}
if($(e).find(".sbar").size()>0){
$(e).find(".sbar").mcustomscrollbar();
}
$(e).addclass("showd");
fun();
}
function hidelayer(e,fun){
if(!fun){fun=function(){};}
if($(".playing").size()>0){
var v=$(".playing")[0];
v.pause();
$(".playing").removeclass("playing");
}
$(e).removeclass("showd");
fun();
}
//自动调整页面高度
function autofoot(){
$(".body").css("min-height",$(window).height()-$(".footer").outerheight()-$(".header").outerheight());
$(".body.page").css("min-height",$(window).height()-$(".footer").outerheight());
}
//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){//class控制
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").size()==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.size()-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.size()){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();
}
//tab切换1
function tabdiv1(prev,next,div,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.size()-1;}
div.filter("[idx!='"+idx+"']").stop(true,true).hide();
div.filter("[idx='"+idx+"']").fadein(speed,function(){
fn($(this));
});
});
$(next).bind("click",function(){
idx++;
if(idx>=div.size()){idx=0;}
div.filter("[idx!='"+idx+"']").stop(true,true).hide();
div.filter("[idx='"+idx+"']").fadein(speed,function(){
fn($(this));
});
});
//if(tab.parent().find(".now").size()==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);
}
//简易iscroll
function miscroll(frame,child,prev,next,speen,fn){
var idx=0,sw=1;
if(!fn){fn=function(){};}
$(frame).stop().animate({scrollleft:0},100);
$(child).eq(0).addclass("now");
$(prev).click(function(){
if(idx>0){
idx--;
run();
}
});
$(next).click(function(){
if(idx<$(child).size()-1){
idx++;
run();
}
});
$(child).click(function(index){
idx=$(this).index();
run();
});
run();
function run(){
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($(frame).scrollleft()+$(frame).width()=w2-w4){
sw=0;
$(frame).stop().animate({scrollleft:w2-w4},speen,function(){sw=1;});
}
$(child).removeclass("now");
$(child).eq(idx).addclass("now");
if(idx==$(child).size()-1){
$(next).addclass("dis");
}
else{
$(next).removeclass("dis");
}
if(idx==0){
$(prev).addclass("dis");
}
else{
$(prev).removeclass("dis");
}
if($(child).size()==1){
$(prev).addclass("dis");
$(next).addclass("dis");
}
}
}
//简易iscroll2,显示溢出项
function miscroll2(frame,child,prev,next,speed){
$(frame).stop().animate({scrollleft:0},0);
$(next).bind("click",function(){
var x=0,w=0;
$(child).each(function(index, element) {
x=$(this).outerwidth()+parseint($(this).css("margin-left")+parseint($(this).css("margin-right")));
w=w+x;
if(w>$(frame).width()+$(frame).scrollleft()){
$(frame).stop().animate({scrollleft:w-$(frame).width()},speed);
return false;
}
});
});
$(prev).bind("click",function(){
var x=0,w=0;
$(child).each(function(index, element) {
x=$(this).outerwidth()+parseint($(this).css("margin-left")+parseint($(this).css("margin-right")));
w=w+x;
if(w+parseint($(this).next().css("margin-left"))>=$(frame).scrollleft()){
w=w-x+parseint($(this).css("margin-left"));
$(frame).stop().animate({scrollleft:w},speed);
$(this).siblings().removeclass("n");
$(this).addclass("n");
return false;
}
});
});
}
//简易iscroll3,整排切换,待修改
function miscroll3(frame,child,prev,next,speed){
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);
$(child).eq(0).addclass("now");
$(prev).click(function(){
w=0,w1=0,w2=1;
idx=parseint($(frame).attr("idx"));
while(1){
if(idx<0){
$(frame).stop().animate({scrollleft:0},speed);
break;
}
w=w+$(child).eq(idx).outerwidth()+parseint($(child).eq(idx).css("margin-left"))+parseint($(child).eq(idx).css("margin-right"));
console.log(w)
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},speed);
$(frame).attr("idx",idx);
break;
}
idx--;
}
});
$(next).click(function(){
w=0,w1=0,w2=1;
idx=parseint($(frame).attr("idx"));
while(1){
if(idx>$(child).size()-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).width()/($(frame).children().width()-($(frame).scrollleft()+$(frame).width()));
}
else if(w1>$(frame).width()){w3=$(frame).width();}
console.log(w2);
$(frame).stop().animate({scrollleft:w1},w2*speed);
$(frame).attr("idx",idx);
break;
}
idx++;
}
});
}
//填满容器
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 videofix(e,w,h,fw,fh){
if(w>=h){
$(e).css({width:fw,height:fw*(h/w),margintop:(fw*(h/w)-fh)*-0.5});
}
else{
$(e).css({width:fh*(w/h),height:fh,marginleft:(fh*(w/h)-fw)*-0.5});
}
}
//数字初始化效果
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 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 "";
}
//获取随机数
function getrandomnum(min,max){
var range = max - min;
var rand = math.random();
return(min + math.round(rand * range));
}
//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){console.log(event.clientx);
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});
}
});
$("body").mouseup(function(event){
sw_m=0;
});
}
//input点击复制
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($) {
$.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);
//判断ie
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;}
}
function device_test(){
var win = window;
var loc = win["location"];
var na = win.navigator;
var ua = na.useragent.tolowercase();
function test(needle) {
return needle.test(ua);
}
var istouch = "ontouchend" in win;
var isandroid = test(/android|htc/) || /linux/i.test(na.platform + "");
var isipad = !isandroid && test(/ipad/);
var isiphone = !isandroid && test(/ipod|iphone/);
var isios = isipad || isiphone;
var iswinphone = test(/windows phone/);
var iswebapp = !!na["standalone"];
var isxiaomi = isandroid && test(/mi\s+/);
var isuc = test(/ucbrowser/);
var isweixin = test(/micromessenger/);
var isbaidubrowser = test(/baidubrowser/);
var ischrome = !!win["chrome"];
var isbaidubox = test(/baiduboxapp/);
var ispc = !isandroid && !isios && !iswinphone;
var ishtc = isandroid && test(/htc\s+/);
var isbaiduwallet = test(/baiduwallet/);
}
//手机跳转
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;
}
}
//是否支持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 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().size()>num){
$(btn).show();
}
else{
$(btn).hide();
}
$(btn).click(function(){
$(e).children().slice(0,parseint($(e).attr("page")+num)).show();
});
}
//子导航定位
function navchildfix(nav,e){
var x=$(nav).offset().left;
var fix=$(e).parent().offset().left;
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"});
}
}
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();
}
//图片惰性加载
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).size()>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).size()>0 && i<1000){
run($("img.unload").eq(0));
}
});
}