Last active
January 18, 2022 16:04
-
-
Save dustinleer/1cb6fa2c4a9ce065dd51ba2d4859dd49 to your computer and use it in GitHub Desktop.
Find the Height of Vertical Slider and animate with button click
This file contains 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
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