soldier soldier - 1 year ago 176
jQuery Question

scrollTop() jQuery not working

i'm using this script as a test but it seems not to be working for me and i don't know why.

$(window).scroll(function() {
if ($(document).scrollTop() > 50) {
} else {

I want to add a class display: none when the screen passes 50px from top. I've tried to load it in a different file or put the script directly on top of the section but it doens't seem to be working.
p.s. i've already loaded another js in the page but it should not be in conflict since doens't animate the same classes
I've loaded both of scripts in the head section by the way
Am i doing something wrong?

Answer Source

Both are working perfectly fine.

  if($(document).scrollTop() > 50 && $(document).scrollTop()<70){
    console.log('document: Yes');
  if($(window).scrollTop() > 50 && $(window).scrollTop()<70){
    console.log('window: Yes');
<script src=""></script>
<div style="height:1000px;"></div>


if($(document).scrollTop() > 50)


if($(window).scrollTop() > 50)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download