4

I have a problem with my add class on scroll code... instead of adding the class after scrolling past the element, it adds the class to every element as soon as the user starts scrolling.

http://sandbox.viaphase.com/ajs-presentation/

$(document).ready(function() {
    $(window).scroll( function(){

        /* Check the location of each desired element */
        $('.animscroll').each( function(i){
            var bottom_of_object = $(this).offset().top + $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            /* If the object is completely visible in the window, fade it it */
            if( bottom_of_window > bottom_of_object ){
                $(this).addClass('SlideUp'); //Adds animation class to element
            }

        }); 
    });
});
2
  • 1
    The code you've posted seems to work for me in this fiddle I made: jsfiddle.net/damo_s/xs9ndk5a Commented Apr 9, 2016 at 3:22
  • I noticed that it works for you in that demo... why do you think it doesn't work on my page? Its quite odd... Commented Apr 9, 2016 at 3:31

1 Answer 1

3

The problem isn't your code, $(window).height() is reporting the SAME as $(document).height();

This is because there is no DOCTYPE in your html.

add:

<!DOCTYPE html> to the top of your page, and your code should work just fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that worked... Can't believe I missed that! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.