我正在建立一个网站,其中包含一页上列出的所有信息。我创建了按钮,当您单击它们时,页面会滚动到您单击的页面部分。一切都很好,除了我想滚动进出。这是我到目前为止的脚本:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top -25
}, 1000);
return false;
}
}
});
});
我只想添加easeInOutExpo动画,但我一直在搞乱代码一小时,我不是最熟练的JQuery,所以我无法弄清楚在哪里添加它。有没有人可以启发我?感谢
答案 0 :(得分:0)
在line 9
}, 1000);
上,你可以在这里定义你的缓动动画:
}, 1000, 'easeInOutExpo');
一如既往,你可以check the documentation on animate()让所有论据都正确无误。
BONUS:考虑e.preventDefault();而不是返回false。