-
-
Save COLABORATI/2854716eff0927267709270839001af3 to your computer and use it in GitHub Desktop.
Scroll to active field in form (typeform style animation) using velocity.js
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
// Insert into some kind of 'focus' action | |
var parent = $(this).parent().parent('.fieldWrap'); // Target a wrapper | |
// Reset active state | |
$('.fieldWrap').removeClass('active'); | |
// Add active state to current field | |
parent.addClass('active'); | |
var fieldHeight = parent.outerHeight(); | |
var windowHeight = $(window).height(); | |
var scrollOffset = (windowHeight - fieldHeight)/2; | |
parent.velocity('scroll', { | |
duration: 300, | |
offset: -scrollOffset, | |
easing: 'easeOutSine' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment