$(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.
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.
What can I do to hide it in the beginning and only show out when scroll > 150?