Skip to content

Instantly share code, notes, and snippets.

@rafaelcavalcante
Created July 24, 2018 14:55
Show Gist options
  • Save rafaelcavalcante/ed2a64b6af01469ad14b13b849974245 to your computer and use it in GitHub Desktop.
Save rafaelcavalcante/ed2a64b6af01469ad14b13b849974245 to your computer and use it in GitHub Desktop.
jQuery(document).ready(function(){
jQuery(window).on('scroll', function(){
var scrollTop = jQuery(window).scrollTop();
var windowHeight = jQuery(window).height();
var windowAxis = scrollTop + (windowHeight / 2);
jQuery('[data-bubble]').each(function(){
var height = jQuery(this).height();
var top = jQuery(this).offset().top;
var axis = top + ( height / 2);
var ratio = parseFloat(jQuery(this).attr('data-ratio'));
var calculus = (windowAxis - axis) * ratio;
jQuery(this).css('transform', 'translateY(' + parseInt(calculus) + 'px)');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment