跳转页面自动滑动到指定 锚点

审核中 jQuery 未结 已结 置顶 精帖
删除 置顶 取消置顶 加精 取消加精
66 0
yswl
yswl VIP3 2023-07-13 17:05:57
悬赏:60金币 编辑此贴

跳转页面自动滑动到指定 锚点

<script>
$(function () {
var url = window.location.href;
if(url.indexOf('#')>=0){
var hrefid = url.substr(url.indexOf('#')+1,url.length);
if(hrefid!=''){
$('html,body').animate({ scrollTop: $("#"+hrefid).offset().top - 100 },500);
}
}
});
</script>