anchorTag跨页面锚点脚本

jQuery(document).ready(function ($) {
if(location.hash){
var id = "#"+location.hash.replace(/%20/g,"_").replace(/[&\|\\\*^%$#@!\-]/g,"");


$(".anchorTag").each(function(){
var thisid = $(this).attr("id");
thisid = thisid.replace(/\s/g,"_").replace(/[&\|\\\*^%$#@!\-]/g,"");
$(this).attr("id",thisid);
console.log($(this).attr("id"))

})

if($(id).length!==0){

$("html, body").animate({
scrollTop: $(id).offset().top + parseInt($(id).data("offset"))
},100)

// setTimeout(function(){
// $("html, body").animate({
// scrollTop: $(id).offset().top + parseInt($(id).data("offset"))
// },100)

// },100)

}
}
})

0 个评论

要回复文章请先登录注册