当我调用“滚动到顶部动作”时,我的代码执行从慢到快的运动,是否有更好的解决方案来解决平滑问题?
我的代码:
(function () {
var top_link = '';
top_link = $(".top");
var pos = top_link.offset();
$(window).scroll(function () {
if ($(this).scrollTop() > 150) {
top_link.fadeIn();
} else if ($(this).scrollTop() <= 150) {
top_link.fadeOut();
}
});
})();
$(".top").click(function () {
$("html, body").animate({
scrollTop: 0
}, 600);
return false;
});
答案 0 :(得分:1)
请更新您的代码:
(function () {
var top_link = '';
top_link = $(".top");
var pos = top_link.offset();
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
top_link.fadeIn('slow');
} else if ($(this).scrollTop() <= 50) {
top_link.fadeOut('slow');
}
});
})();
$(".top").click(function () {
$("html, body").animate({
scrollTop: 0
}, 500);
return false;
});
谢谢