Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scrolling to HTML element
<a href="#" data-go="#node-element" class="go">Go to</a>
<script type="text/javascript">
$(".go").click(function(e){
//We prevent the default scroll
e.preventDefault();
var $this = $(this),
to = $this.attr("data-go"),
topSlider = $(to).position().top;
//We scroll to to the DOM element
$("body, html").animate({
scrollTop : topSlider
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.