Scroll attenuation

I added a script that I found here. It works. However, I was stuck trying to apply a fade effect to it. At that moment, it just turns off.

script type="text/javascript">


    $(document).ready(function() {


        $(window).scroll(function () {
              var height = $('body').height();
              var scrollTop = $('body').scrollTop();
              var opacity = 1;


              if(scrollTop > 400) {
                  opacity = 0;
              }

           $('.social').css('opacity', opacity);
        });
    });
</script>

EDIT: I knit this and it works. Many thanks to the guys:

<script type="text/javascript"> 
$(window).scroll(function() { 
// The social div 
var $socialDiv = $('.social'); 

//Get scroll position of window 
var windowScroll = $(this).scrollTop(); 

//Slow scroll of social div and fade it out 
$socialDiv.css({ 
'margin-top' : - (windowScroll / 3) + "px", 
'opacity' : 1 - (windowScroll / 550) 
}); 
}); 
</script>
+5
source share
1 answer

You must use . animate () or . fadeTo () for this effect.

Using .css('opacity', opacity);will make your item disappear suddenly.

+2
source

All Articles