Fade Out On Scroll

冷暖自知 提交于 2019-12-06 16:03:03

问题


I'm relatively new to JQUERY and I'm looking for a point in the right direction.

How do I achieve a fade on scroll effect?

Like http://fearthegrizzly.com/ or http://davegamache.com

Ideally I'd like the option to drop whatever image I want to fade out into a div. If that's possible.

It's probably worth mentioning I want to implement this on Cargo Collective.

Thanks


回答1:


Tip for asking question: Don't just tell us what you want. We're not here to do your work for you. Show us what you've tried so we can help fix it.

That being said, this is a start...

When the window's scroll top position is greater than 20px, it fades a div out, when you scroll back up, it fades it back in.

$(window).scroll(function(){
   if($(window).scrollTop()<20){
         $('.fader').stop(true,true).fadeIn("slow");
   } else {
         $('.fader').stop(true,true).fadeOut("slow");
   }
});

DEMO




回答2:


fearthegrizzly.com uses a .css() method. You could try:

$(window).scroll(function() {
    $(".header-image").css({
    'opacity' : 1-(($(this).scrollTop())/250)
    });          
});

You scroll down 250px, the property is fully faded out and vice versa.



来源:https://stackoverflow.com/questions/11462751/fade-out-on-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!