[英]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);
})
});
Above is javascript code for my back-to-top button and I want it show out only when I scroll the page. 上面是我的返回页首按钮的javascript代码,我只希望在滚动页面时才显示它。
However, I found out that this button will show out in the beginning when I refresh the page and hide again when scroll < 150 and show again when scroll > 150. 但是,我发现刷新页面时此按钮将在开始时显示,并在滚动<150时再次隐藏,在滚动> 150时再次显示。
What can I do to hide it in the beginning and only show out when scroll > 150? 我该怎么做才能在开始时将其隐藏,仅在滚动> 150时才显示?
use below code. 使用以下代码。 hide button on page load button will display as per your condition 150 >
页面加载按钮上的“隐藏”按钮将根据您的条件显示150>
$(document).ready(function() {
$('.back-to-top').hide();
// your code here
or using css 或使用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.