$(function () { // 默认运动 jQuery.easing.def = "easeInOutCubic"; // 获取数据 var h_yuansuhei = $(".h_ys").parent().height(); var h_yuansuoffTop = $(".h_ys").parent().offset().top; // 执行锚点位置,以及进行的过渡运动效果 $(".hao_maodian").bind("click touch", function () { $('html,body').animate({ scrollTop: ($($(this).attr('href')).offset().top - h_yuansuhei) }, { duration:1200, easing:"easeInOutCubic" }); }); // 如果不是定位,则计算模块高度,给模块邻近下面的模块添加当前模块的高度 $(window).scroll(function () { if ($(this).scrollTop() >= h_yuansuoffTop) { $(".h_ys").parent().addClass("h_dingwei"); $(".h_ys").parent().next().css("margin-top", h_yuansuhei); } else { $(".h_ys").parent().removeClass("h_dingwei"); $(".h_ys").parent().next().css("margin-top", "0"); } }); });