【发布时间】:2020-05-13 20:44:17
【问题描述】:
我有这个脚本,我想在其中添加一些缓动以使整个滚动效果更平滑一点:
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
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) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top}, 1000,
function() {
var $target = $(target);
$target.focus();
if ($target.is(":focus")) {
return false;
} else {
$target.attr('tabindex','-1');
$target.focus(); // Set focus again
};
});
}
}
});
所以我选择了这一行并添加了'easeOutExpo',但不幸的是它不起作用。知道我做错了什么吗?
scrollTop: target.offset().top}, 1000, 'easeOutExpo',
【问题讨论】:
标签: javascript jquery smooth-scrolling