jquery - Background to Scroll Vertically a Certain Amount -
we've got backgrounds on our site , wondering easiest way stop background scrolling further amount?
so if scroll-y it's infinite in respect how content have. how stop bg scrolling after let's 250px, 100px etc
thanks
i think you'd want this, haven't run code may not perfect, should show technique (may have mixed 'fixed' , 'scroll' bits - should able tell pretty quickly)
$(window).scroll(function(){ var d = $(window).scrolltop(); if(d > 250){ $('#image-div').css('background-attachment', 'fixed'); }else{ $('#image-div').css('background-attachment', 'scroll'); } }); in psuedo code: when window scrolls, grab variable (d) equal screen 'scrolled' amount, if on x amount, attach or release attachment.
its worth adding function fire every time page scrolled, there may methods bit lighter on processor power, they're going little more complicated.
Comments
Post a Comment