$(function() { var mao = $("#" + getParam("m")); //获得锚点 if (mao.length > 0) {//判断对象是否存在 var pos = mao.offset().top; var poshigh = mao.height(); $("html,body").animate({ scrollTop: pos-poshigh-30 }, 3000); } });