How to make section fade on scroll?

I am a registered user

I am trying to make a section of my website fade out on scroll. I tried looking at other questions, but none helped. Here is the link to my code : http://bit.ly/1BmYnvo

Any help would be appreciated. If you could tell me why your code works, that would be great too!

Thanks

Marko Grešak

In your js, you're trying to select element(s) with .social class. The class is not set anywhere, therefore jQuery won't select any element, thus not changing opacity value on scroll.

Fix: add class="social" to your div.

// As @Bojangles recommended, search for element only once to improve performace.
var $socialDiv = $('.social');
 
$(window).scroll(function() {
  //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)
  });
});
div {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 500%;
  background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="social">
  Hi!
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make the footer on scroll fade in, in jquery?

In Vue.js how to make a nav fade in on scroll down event and fade out where scroll pageYOffset = 0

How to make a React component fade in on scroll using IntersectionObserver, but only once?

How do I make an image fade out but stay in place on scroll?

How to make fixed scroll stick only till a certain section

how to change section on scroll?

How to make MUI Fade fade in on render?

CSS how to make an element fade in and then fade out?

How to make a 50% fade in and a 100% fade out?

Make an element scroll inside a grid section

How to scroll to the bottom of a section with IGListKit

How to fade in while scroll down with jquery

carouFredSel: How to make slides fade

How to make the text fade for seconds

How to make text fade out

How to make Section collabsible?

How to make section in pycharm

Flutter AppBar make bottom widget slowly fade on scroll

How to make a created div in Javascript fade in and fade out?

How to make text fade in instantly but fade out slowly in HTML/CSS?

Certain element won't fade in when I scroll past a certain portion of a section

how to make smooth scroll?

How to make scroll menu?

How to make TScrollingWinControl scroll

How to make virtual scroll?

React Fullpage: How to scroll a portion of a section without scrolling the whole section

How to programmatically have UITableView scroll to a specific section

How to scroll to section with vue-smooth-scrollbar?

How to scroll to last row of the last section in a UITableView?