Skip to content

Instantly share code, notes, and snippets.

@jorgechavz
Created June 19, 2015 23:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgechavz/1015467773de5e008bbf to your computer and use it in GitHub Desktop.
Save jorgechavz/1015467773de5e008bbf to your computer and use it in GitHub Desktop.
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