点击页面锚点的时候
$(function(){
$('a[href*=#],area[href*=#]').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var pagehash = this.hash;
console.log(pagehash)
$(".second_category_60").removeClass("on");
$(".second_category_58").removeClass("on");
$(".second_category_59").removeClass("on");
$(".second_category_15").removeClass("on");
if(pagehash=="#miao21"){
$(".second_category_60").addClass("on");
}
if(pagehash=="#miao11"){
$(".second_category_58").addClass("on");
}
if(pagehash=="#miao31"){
$(".second_category_59").addClass("on");
}
if(pagehash=="#miao41"){
$(".second_category_15").addClass("on");
}
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
var targetOffset = $target.offset().top-100;
$('html,body').animate({
scrollTop: targetOffset
},
600);
return false;
}
}
});
});
进入页面的时候
var myHash2 = location.hash;
if(myHash2=="#miao11"){
$('body,html').animate({scrollTop:$(myHash2).offset().top-100},1000);
}
if(myHash2=="#miao21"){
$('body,html').animate({scrollTop:$(myHash2).offset().top-100},1000);
}
if(myHash2=="#miao31"){
$('body,html').animate({scrollTop:$(myHash2).offset().top-100},1000);
}
if(myHash2=="#miao41"){
$('body,html').animate({scrollTop:$(myHash2).offset().top-100},1000);
}