我看了所有其他问题,无法弄清楚我的错误。该函数应该滚动到hash onClick。
$('.scrolltohash').click(function(e) {
//alert('We Got Here');
var scrolltothis = $(this).attr('href');
var $scrolltothis = $(scrolltothis);
//alert($scrolltothis);
var position = $scrolltothis.offset().top;
//alert(position);
$('html, body').animate({
scrollTop: position
}, 2000);
e.preventDefault();
});
我收到以下错误
TypeError:$ scrolltothis.offset(...)未定义
小提琴
答案 0 :(得分:1)
示例中的ID sticky-header
没有任何内容。什么都没有偏移是undefined
。