Add class to div when in viewport

$(window).scroll(function(){ inViewport(); }); $(window).resize(function(){ inViewport(); }); function inViewport(){ $('.your-div').each(function(){ var divPos = $(this).offset().top, topOfWindow = $(window).scrollTop(); if( divPos < topOfWindow+400 ){ $(this).addClass('hello'); } }); }

1 Response

very nice

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.