$(function() { //右侧悬浮窗出现效果 $('body').on('mouseenter','.floatWindow',function(){ $('.floatWindow_box').stop(true).fadeIn(); }) $('body').on('mouseleave','.floatWindow',function(){ $('.floatWindow_box').stop(true).fadeOut(); }) //导航栏hover效果 $('body').on('mouseenter','.headerNav>li',function(){ $(this).find('.headerDown').stop(true).show(); }) $('body').on('mouseleave','.headerNav>li',function(){ $(this).find('.headerDown').stop(true).hide(); }) }) $(window).scroll(function () { var h = $(window).scrollTop() if (h > $('.warpper').offset().top - 150) { $('.publicNav').addClass('fiexd'); }else{ $('.publicNav').removeClass('fiexd'); } }) // 注意在设置所有DOM高度代码之后 window.onload=function(){ $("html,body").animate({scrollTop:0},0) var url = window.location.toString(); var id = url.split("#")[1]; if(id && id!=""){ if($("#"+id).length>0){ var t = $("#"+id).offset().top-80; //80代表的是导航栏的高度 $("html,body").animate({scrollTop:t},10) } } $('a').click(function(){ if($(this).attr("href") && $(this).attr("href").split("#")[1]){ var a=$(this).attr("href").split("#")[1]; var p=$("#"+a).offset().top-80; //80代表的是导航栏的高度 $("html,body").animate({scrollTop:p},10); } }) }