Skip to content

Instantly share code, notes, and snippets.

@dustinleer
Last active January 18, 2022 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinleer/1cb6fa2c4a9ce065dd51ba2d4859dd49 to your computer and use it in GitHub Desktop.
Save dustinleer/1cb6fa2c4a9ce065dd51ba2d4859dd49 to your computer and use it in GitHub Desktop.
Find the Height of Vertical Slider and animate with button click
jQuery(window).on('load resize scroll', function(){
jQuery('.home-hero').next().attr('id', 'after-hero'); //adds and anchor id to the sibling element to the home-hero
var numItems = jQuery('.home-hero__item').length, //finds all the items
numItems = numItems - 1, //subtracts one item as the first slide is not a true slide
outerHeightSlide = jQuery('.slide-0').outerHeight(), //finds the height of the first slide item
outerHeightSlides = jQuery('.slide-1').outerHeight(), //finds the height of all the slides in the slider
scroll = jQuery(window).scrollTop(), //find scroll position
allSlidesHeight = outerHeightSlides * numItems + outerHeightSlide - scroll; //does the math to get how far to scroll to the main content
/**
* Adds click function to scroll to the main content
*/
jQuery('.hero-skip.button').on('click tap', function () {
jQuery('html, body').stop().animate({ scrollTop: '+=' + allSlidesHeight }, 800);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment