jquery - Can't figure out why this doesn't work -
$(function () { // document ready $(window).scroll(function() { var top_offset = $('body').offset().top; if ((top_offset <= 650)) { $('.fluid-width-video-wrapper').addclass('fluid-width-video-wrapper-bottom'); } else { $('.fluid-width-video-wrapper').removeclass('fluid-width-video-wrapper-bottom'); } }); });
i literally can't figure out why doesn't work, should add class .fluid-width-video-wrapper if page scrolled more 650px, or remove class if isn't.
can show me my-no-doubt idiotic mistake here?
offset
gives top , left pixel offsets of element relative document.
since body element starts @ top left corner, it'll give top:0
, left:0
99% of time, unless you've done special body tag in css.
what want $(window).scrolltop()
which tells how far down page have scrolled.
Comments
Post a Comment