我成功解決了我的問題!
CSS:
.ev-scrolltop{
opicity: 0;
}
.ev-scrolltop.show{
opicity: 1;
transition: opacity .4s ease-out;
}
JS:
$(document).ready(function() {
var t, n = $(window),
e = $(".ev-scrolltop"),
o = !1,
i = function() {
if (n.scrollTop() < n.height()) return e.removeClass("show"), !1;
t && (clearTimeout(t), t = null), t = setTimeout(function() {
o && (n.scrollTop() > n.height() ? e.addClass("show") : e.removeClass("show"), o = !1);
}, 500), o || (o = !0, e.removeClass("show"));
};
n.on("scroll", i), i(), $(document).on("click", ".ev-scrolltop", function() {
$("html, body").stop().animate({
scrollTop: 0
}, 500, "easeOutCirc").promise().done(function() {
o = !1, e.removeClass("show");
});
});
}
也許你會從中得到[鏈接]一些幫助(https://stackoverflow.com/questions/9144560/jquery-滾動檢測當用戶停止滾動) –
@HimanshuUpadhyay謝謝!但它仍然不能解決我的問題。 –