Skip to content

Instantly share code, notes, and snippets.

@RStankov
Created June 8, 2011 12:34
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 RStankov/1014327 to your computer and use it in GitHub Desktop.
Save RStankov/1014327 to your computer and use it in GitHub Desktop.
$(document).delegate('[data-action="scroll"]', 'click', function() {
var scrollToId = $(this).attr('href').split('#')[1];
if (document.getElementById(scrollToId)){
$.scrollTo('#' + scrollToId, {
duration: 800,
onAfter: function(){ window.location.hash = '#' + scrollToId; }
});
return false;
}
});
$(document).delegate('[data-action="print"]', 'click', function() {
window.print();
});
<a href="faq#question-1" data-action="scroll">Question 1</a>
<a href="faq#question-2" data-action="scroll">Question 2</a>
<button data-action="print">Print</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment