我看了所有其他問題,並不能找出我有什麼問題。這個函數應該滾動到散列onClick。平滑滾動哈希沒有臃腫的插件3
$('.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();
});
我收到以下錯誤
類型錯誤:$ scrolltothis.offset(...)是未定義
小提琴
https://jsfiddle.net/853jozk4/3/
它應該說的立場,但它並沒有真正執行到那麼遠。 –