Skip to content

Instantly share code, notes, and snippets.

@psycalc
Last active September 18, 2016 10:51
Show Gist options
  • Save psycalc/2a2b93ba866fab06f3c27512ea115e16 to your computer and use it in GitHub Desktop.
Save psycalc/2a2b93ba866fab06f3c27512ea115e16 to your computer and use it in GitHub Desktop.
menu auto scroll
//dependecy: jQuery
//just scroll to element with data-slice value
function goToByScroll(dataslide) {
//jQuery function animate do that work
var elementWithDataSlideAttr = $('.slide[data-slide="' + dataslide + '"]');
//offset it is object with tho properties left and top (px from the left/top accordingly)
var offsetOfThatElement = elementWithDataSlideAttr.offset();
var configurationPlainObjectForAnimateFunction = {
scrollTop: offsetOfThatElement.top
}
htmlbody.animate(configurationPlainObjectForAnimateFunction, 2000, 'easeInOutQuint');
}
links.click(function (e) { //main menu event click handler
e.preventDefault(); //prevent default link action
dataslide = $(this).attr('data-slide'); //get data from data-slide attribute and save it to dataSlide variable
goToByScroll(dataslide); //function that just scroll to specifice attribute value (for exmaple about it is 2)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment