0
我有一些問題。我有滾動到滾動aniamtion選定元素的JavaScript功能。 這工作得很好,但問題是當我滑動/向下滑動(顯示隱藏)某些元素。動畫滾動到#hash頁面上隱藏的元素
如果點擊鏈接有類.show
我表演關於部分。如果鏈接沒有這個類,我使用.slideUp
函數來隱藏這個元素。這造成了錯誤,因爲現在襯裏並不精確(它錯誤地指向錯誤的地方)。它看起來像JavaScript考慮隱藏元素的高度,並計算所有錯誤。我不知道如何解決這個問題。 感謝您的幫助。
var $root = $('html, body');
$(document).on('click','.scroll-ani', function(event){
if ($(this).hasClass('show')) {
if ($('#about').is(':hidden')) {
$('#about').slideDown();
}
} else {
// if i replace slideUp with .hide() it will work well, but will not animate this slideUp effect.
$('#about').slideUp();
}
var hash = this.hash;
if (hash && this.href.slice(0, -hash.length-1) == location.href.slice(0, -location.hash.length-1)) {
$root.animate({
scrollTop: $(hash).offset().top
}, 'normal', function() {
location.hash = hash;
});
return false;
}
});