[英]How to add easing to smooth scrolling?
I have this script where I'd like to add some easing to make the whole scrolling effect a little smoother:我有这个脚本,我想在其中添加一些缓动以使整个滚动效果更平滑一点:
$('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
};
});
}
}
});
So I picked this line and added 'easeOutExpo'
, but unfortunately it didn't work.所以我选择了这条线并添加了'easeOutExpo'
,但不幸的是它没有用。 Any idea what I'm doing wrong?知道我做错了什么吗?
scrollTop: target.offset().top}, 1000, 'easeOutExpo',
https://jsfiddle.net/3gb4s2af/1/ https://jsfiddle.net/3gb4s2af/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.