Last active
January 22, 2019 23:09
-
-
Save odessy/81bfc35350460c273faa8ccae96cfe24 to your computer and use it in GitHub Desktop.
make call to action sticky
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
| jQuery(function($) { | |
| var $window = $(window), | |
| ctaPosition = parseInt($('#call-to-action').offset().top) - parseInt($('#call-to-action').height()) - window.innerHeight, | |
| cta = $('#call-to-action'); | |
| // Run this on scroll events. | |
| $window.scroll(function() { | |
| console.log( $window.scrollTop() + ' - ' + ctaPosition ); | |
| if ( $window.scrollTop() < ctaPosition ) { | |
| // Make the div sticky. | |
| cta.css({'position':'fixed','bottom':'0', 'width': '100%', 'z-index': '9999'}); | |
| } | |
| else { | |
| // Unstick the div. | |
| cta.css({'position':'relative'}); | |
| } | |
| }); | |
| $window.scroll(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment