Created
October 3, 2019 17:38
-
-
Save KustomDeveloper/9f55df58421380bc26f54155067d2794 to your computer and use it in GitHub Desktop.
Form scroll functions and fixed form for landing pages
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
| //Scroll to form on button click and focus on first input | |
| $('#up-to-form').on('click', function(e) { | |
| e.preventDefault(); | |
| $('html, body').animate({ | |
| scrollTop: $('.form-container').offset().top - 20 | |
| }, 'slow'); | |
| $('.form-container form input').first().focus(); | |
| }); | |
| //Make form fixed so it stays in view on desktop viewport | |
| $(window).scroll(function() { | |
| var scroll = $(window).scrollTop(); | |
| if (scroll >= 50) { | |
| $(".form-fixed-wrapper").addClass("fixed-scroll"); | |
| } | |
| if (scroll <= 50) { | |
| $(".form-fixed-wrapper").removeClass("fixed-scroll"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment