Created
July 17, 2015 22:21
-
-
Save kier0/291c5d5a8dbf5931ee6d to your computer and use it in GitHub Desktop.
Make top logo or nav fade on scroll down, and reappear on scroll up. var triggerHeight = 50; ---->>> is height of nav or logo so it downs face before you scroll past it.
Scrolling up/down triggers class swap - use CSS to set opacity and animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Logo Fade | |
| <?php wp_enqueue_script('jquery'); ?> | |
| <script> | |
| var didScroll; | |
| var lastScrollTop = 0; | |
| var delta = 5; | |
| var triggerHeight = 50; | |
| jQuery(window).scroll(function(){ | |
| didScroll = true; | |
| }); | |
| setInterval(function() { | |
| if (didScroll) { | |
| hasScrolled(); | |
| didScroll = false; | |
| } | |
| }, 250); | |
| function hasScrolled() { | |
| var st = jQuery(this).scrollTop(); | |
| // Make sure they scroll more than delta | |
| if(Math.abs(lastScrollTop - st) <= delta) | |
| return; | |
| if (st > lastScrollTop && st > triggerHeight){ | |
| // Scroll Down | |
| jQuery('#the-element-to-fade').removeClass('opaq').addClass('glass'); | |
| } else { | |
| // Scroll Up | |
| if(st + jQuery(window).height() < jQuery(document).height()) { | |
| jQuery('#the-element-to-fade').removeClass('glass').addClass('opaq'); | |
| } | |
| } | |
| lastScrollTop = st; | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #the-element-to-fade{ | |
| transition: opacity .5s ease-in-out; | |
| -moz-transition: opacity .5s ease-in-out; | |
| -webkit-transition: opacity .5s ease-in-out; | |
| } | |
| #the-element-to-fade, | |
| #the-element-to-fade.opaq { | |
| opacity: 1; | |
| } | |
| #the-element-to-fade.glass { | |
| opacity: 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment