有人遇到过这个问题吗?
通过 anchor 标记重定向时,网站不会滚动到正确的位置。
例如,在 about.html
页面上,我单击一个 anchor 标记,将我带到 index.html#form
。
它具有随机行为。有时会带我进入表格,有时不会。在手机上解决这个问题。
最佳答案
您网站 Assets 中的以下脚本 ~ js/script.js
是罪魁祸首:
//SMOOTH PAGE SCROLL
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if(this.href != undefined){
var a = this.href.split('#');
if(a[1] != 'collapseOne' && a[1] != 'collapseTwo' && a[1] != 'collapseThree' && a[1] != 'collapseFour' && a[1] != 'collapseFive'
&& a[1] != 'collapseSix' && a[1] != 'collapseSeven' && a[1] != 'collapseEight' ) {
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
}, 1000);
return false;
}
}
}
}
});
});
它提供平滑的滚动,并用 (root/index.html)
替换更改后的 URL (root/index.html#miniForm)
,这使得无法导航到特定的 div
。
您可以替换 URL 替换代码段,并可以使用提供的功能来实现平滑滚动。
关于javascript - 使用无法在手机上正常工作的 anchor 标记从页面重定向到其他页面的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43428984/