$(function(){ var totop = $('#to-top'); //if($(window).width() > 768){ $(".nav .item").hover(function(){ var documentwidth = $(document).width(); var navwidth = $(this).width(); var navx = $(this).offset().left; var centerx = navx + (navwidth/2); var maxleft = (documentwidth - 1200) /2 +1200; var minleft = (documentwidth - 1200) /2; var boxwidth = 0; var left,maxwidth; var offsetleft = $(this).find('.icon-nav').length ? 104 : 54; $(this).find(".secord>li").each(function(){ boxwidth += $(this).width() + offsetleft; }); boxwidth-=offsetleft == 104 ? 0 : 54; if(boxwidth > 1200){ boxwidth = 1200; } maxwidth = centerx + (boxwidth/2); if(maxwidth > 1200){ left = centerx - (boxwidth/2) - (maxwidth - 1200); }else{ left = centerx - (boxwidth/2); if(left < 0){ left = 0; } } if(documentwidth > 1200){ left = left - (documentwidth - 1200)/2; } if(documentwidth < 1200){ $(this).find(".secord").css("margin-left","0px"); } //$(this).find(".secord").css("position","relative"); $(this).find(".secord").css("display","block"); if($(this).find(".secord").css("margin-left") == "0px"){ $(this).find(".secord").css("margin-left",left); } }); //} //判断是否有滚动条 totop.on('click',function () { $('body,html').animate({'scrolltop':0},300) }); $(window).on('scroll',function () { if($(this).scrolltop() > 200){ totop.show() }else{ totop.hide() } }) });