【发布时间】:2019-03-20 04:46:29
【问题描述】:
我需要编辑下面的代码。现在它适用于 url (www.mypage.com/#contact) 中的锚点。我需要根据以下示例修改此代码以保存到 var target 变量中:
www.mypage.com/#contact > 目标 = 联系人
www.mypage.com/page.html > 目标 = 页面
www.mypage.com/page.html#contact > 目标 = 联系人
$('a.js-scroll-trigger[href*="#"]').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: (target.offset().top - 70)
}, 1000, "easeInOutExpo");
return false;
}
}
});
感谢您的帮助。
【问题讨论】:
-
怎么样:
www.mypage.comandwww.mypage.com/targetandwww.mypage.com/target/andwww.mypage.com#andwww.mypage.com/#andwww.mypage.com/page.html#? -
有什么问题?