Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Div when scroll position

First of all i would like to refer to this website: http://annasafroncik.it/ I love the way the animations come into view. Is it hard to create a similar function in jquery? Are there any plugins to create such an effect?

Hope someone will help me out.

like image 880
idbranding Avatar asked Feb 01 '12 14:02

idbranding


People also ask

How do I display the content while scrolling in HTML?

First wrap whatever your text or content that you want to show on scroll, in one div so that you can show hide the div depending upon the scroll. Write two classes for your target div. Hope it will solve your problem.

How do I scroll to a specific div in HTML?

If you want to scroll the current document to a particular place, the value of HREF should be the name of the anchor to which to scroll, preceded by the # sign. If you want to open another document at an anchor, give the URL for the document, followed by #, followed by the name of the anchor.

How do I know my scroll position?

To get or set the scroll position of an element, you follow these steps: First, select the element using the selecting methods such as querySelector() . Second, access the scroll position of the element via the scrollLeft and scrollTop properties.


1 Answers

Basically, you want to add a "hideme" class to every element you want hidden (then you set that class to "opacity:0";

Then, using jQuery you set a $(window).scroll() event to check the location of the bottom of every "hideme" element against the bottom edge of your visible window.

Here's the meat of it ...

/* Every time the window is scrolled ... */ $(window).scroll( function(){      /* Check the location of each desired element */     $('.hideme').each( function(i){          var bottom_of_object = $(this).offset().top + $(this).outerHeight();         var bottom_of_window = $(window).scrollTop() + $(window).height();          /* If the object is completely visible in the window, fade it in */         if( bottom_of_window > bottom_of_object ){              $(this).animate({'opacity':'1'},500);          }      });   }); 

Here's a full jsfiddle: http://jsfiddle.net/tcloninger/e5qaD/

like image 71
Timothy Aaron Avatar answered Sep 27 '22 17:09

Timothy Aaron