滚动到页面上的 ID 未正确计算偏移量
Scroll to ID on page not calculating offset correctly
$('.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);
}
相关文章:
- 添加新数据时D3.JS条形图列偏移量
- 当偏移量改变时滚动顶部
- 引导数据偏移量底部
- 可以在调整窗口大小时重新调整stellar.js的元素偏移量
- 可滚动元素,如何在调整大小时更改顶部偏移量
- 使用JavaScript日期的任何时间的时区偏移量
- 时刻时区:UTC 偏移量差异
- jQuery偏移量顶部没有'工作不正常
- 如何获取当前时区偏移量(并正确格式化)
- d3.mouse 偏移量返回的值不正确
- jQuery根据鼠标位置计算DIV偏移量和边界
- 时区偏移量计算
- 在 JavaScript 中给定时区字符串的情况下计算 UTC 偏移量
- 如何计算鼠标与指定偏移量的移动距离
- jQuery 偏移量在某些页面上计算不正确
- 新偏移量更新字体大小后不计算高度
- 滚动到页面上的 ID 未正确计算偏移量
- 如何在Javascript中计算dblclick事件的文本偏移量
- 计算 HTML5 视频的偏移量
- 使用偏移量计算JavaScript日期时间