$('.home-slide-button').on('click', function (e) {
var matches = window.location.hash.match(/^#([0-9]+)$/);
if (matches) {
var number = matches[1];
$('html, body').animate({
scrollTop: $('#' + number).offset().top -150
}, 1500);
}
});
当单击"主页"页面(http://buchbinderei.it/)中的产品链接时,它应重定向到"产品"页面(http://buchbinderei.it/produkte/),并顺利向下滚动到单击的产品。一些它如何不计算前 -150 偏移量......有什么建议吗?
实际错误的偏移位置:https://www.dropbox.com/s/m3cbinuyl4d3pgv/Screenshot%202016-01-24%2022.47.55.png?dl=0
所需偏移位置:https://www.dropbox.com/s/y0lhldjvult9kdg/Screenshot%202016-01-24%2022.48.49.png?dl=0
这解决了我的问题:
if (location.hash) {
setTimeout(function() {
var matches = window.location.hash.match(/^#([0-9]+)$/);
if (matches) {
var number = matches[1];
$('html, body').animate({
scrollTop: $('#' + number).offset().top -180
}, 500);
console.log('enter');
}
}, 1);
}