#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189

    $(window).scroll() not triggering event.


    No error, but it just never triggers.


    Code:
    	$(document).ready(function() {
    		console.log('got here');
    		$(window).scroll(function() {
    			console.log('Log this');
    		});
    	});
    THis has been placed near the bottom of this page

    I've been beating my hear for some time.

    Looking for some advice please
    Thomas Tremain
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,165
    Rep Power
    184
    I think you just need to use the $(window) object outside of the $(document) object; something like this:
    Code:
    <script>
    $(window).on('scroll',function() {
        console.log('Log this');
     });
    </script>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Originally Posted by web_loone08
    I think you just need to use the $(window) object outside of the $(document) object; something like this:
    Code:
    <script>
    $(window).on('scroll',function() {
        console.log('Log this');
     });
    </script>
    I just tried your suggestion, and got the same results. but thank you
    Thomas Tremain
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,165
    Rep Power
    184
    Are you including the jQuery Library? Because I tested the code I provided you and it works fine.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Originally Posted by web_loone08
    Are you including the jQuery Library? Because I tested the code I provided you and it works fine.
    Yes, jquery 1.10.2

    Tonight when I have a bit more time, I think I'll try a test page stripping out some of the other things that are used on this one, to see if there is a conflict somewhere.
    Thomas Tremain
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Tested both methods with no other javascript in the entire page, short of loading jquery.

    I even tried a different version of the jquery library.

    A test page is now here:
    This link

    Yet, I can find it working on this sample page

    Puzzled
    Thomas Tremain
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189

    Solved


    It was not conflicting with the jquery in any other library, but it was conflicting with CSS in one of them.
    Thomas Tremain
  14. #8
  15. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,165
    Rep Power
    184
    Glad you got it working, although I am not sure your CSS is conflicting with your code. You have a "s" variable within your $(window).scroll() function; that does not appear to be defined within your JavaScript/jQuery. The developer console should have been showing you this error, because it did in mine. Not 100% sure, if this could have been the issue or not; since you may have stripped out some other code and forgot to remove the "s" variable reference, throughout your jQuery function; but if some type of CSS error corrected this issue..., then that's good as well.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Originally Posted by web_loone08
    Glad you got it working, although I am not sure your CSS is conflicting with your code. You have a "s" variable within your $(window).scroll() function; that does not appear to be defined within your JavaScript/jQuery. The developer console should have been showing you this error, because it did in mine. Not 100% sure, if this could have been the issue or not; since you may have stripped out some other code and forgot to remove the "s" variable reference, throughout your jQuery function; but if some type of CSS error corrected this issue..., then that's good as well.
    The s. was part of some stripped out code. It wasn't showing as an error, because that function was never running.

    On of the libraries was setting the following CSS. I really don't know if it was this specifically, or a combination of this and something else, but as soon as this was removed from the page, all worked well.

    Code:
    html, body {height: 100%;overflow: auto;}
    Thomas Tremain
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Smile


    Did you insert jquery.js file in your code file.


    if yes then try below


    jQuery(document).ready(function() {
    console.log('got here');
    jQuery(window).scroll(function() {
    console.log('Log this');
    });
    });

IMN logo majestic logo threadwatch logo seochat tools logo