Skip to content

Instantly share code, notes, and snippets.

@COLABORATI
Forked from nathanhornby/typeform-velocity.js
Created June 28, 2016 21:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save COLABORATI/2854716eff0927267709270839001af3 to your computer and use it in GitHub Desktop.
Save COLABORATI/2854716eff0927267709270839001af3 to your computer and use it in GitHub Desktop.
Scroll to active field in form (typeform style animation) using velocity.js
// 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