Skip to content

Instantly share code, notes, and snippets.

@KustomDeveloper
Created October 3, 2019 17:38
Show Gist options
  • Select an option

  • Save KustomDeveloper/9f55df58421380bc26f54155067d2794 to your computer and use it in GitHub Desktop.

Select an option

Save KustomDeveloper/9f55df58421380bc26f54155067d2794 to your computer and use it in GitHub Desktop.
Form scroll functions and fixed form for landing pages
//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