Created
April 23, 2018 13:19
-
-
Save NickDeckerDevs/b1ae3fa04add1208a7477446249a8e62 to your computer and use it in GitHub Desktop.
menu to sticky from relative and a slideout/in animation for an example of scrolling cta on side that slides outs
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
| // for the movement and keeping it at a fixed position, | |
| // set elbottom to the height of the screen or the place where you want it to stick | |
| jQuery(function() { | |
| var $window = jQuery(window), | |
| $stickyEl = jQuery('.sidemenu'), | |
| elTop = $stickyEl.offset().top, | |
| elBottom = jQuery('.specials-wrapper').parent().next().offset().top - $stickyEl.height() - 20; | |
| $window.scroll(function() { | |
| $stickyEl.toggleClass('visible', $window.scrollTop() < elBottom && $window.scrollTop() > elTop); | |
| }); | |
| }); | |
| // use this for your slideout | |
| $(function() { | |
| var slidebox = $('#slidebox'); | |
| if (slidebox.length>0) { | |
| $(window).scroll(function(){ | |
| var distanceTop = $('.hero-section').offset().top - $(window).height(); | |
| if ($(window).scrollTop() > distanceTop){ | |
| slidebox.animate({'right':'0px'},300); | |
| } | |
| else{ | |
| slidebox.stop(true).animate({'right':'-430px'},100); | |
| } | |
| }); | |
| $('#slidebox .close').on('click',function(){ | |
| $(this).parent().remove(); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment