[英]How to not show back-to-top button when refresh the page?
$(document).ready(function() {
$(window).scroll(function() {
if ($(this).scrollTop() > 150) {
$('.back-to-top').fadeIn(500);
} else {
$('.back-to-top').fadeOut(500);
}
});
$('.back-to-top').click(function(event) {
event.preventDefault();
$('html, body').animate({scrollTop: 0}, 500);
})
});
上面是我的返回页首按钮的javascript代码,我只希望在滚动页面时才显示它。
但是,我发现刷新页面时此按钮将在开始时显示,并在滚动<150时再次隐藏,在滚动> 150时再次显示。
我该怎么做才能在开始时将其隐藏,仅在滚动> 150时才显示?
使用以下代码。 页面加载按钮上的“隐藏”按钮将根据您的条件显示150>
$(document).ready(function() {
$('.back-to-top').hide();
// your code here
或使用CSS
.back-to-top{
display:none;
}
<style>
.back-to-top{
display:none;
}
</style>
将此添加到您的CSS中:
.back-to-top {opacity:0;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.