main.js 572 B

12345678910111213141516171819202122232425
  1. /**
  2. * Animated scroll to named anchors.
  3. */
  4. $(document.body).on('click', 'a', function () {
  5. var href = $(this).attr('href')
  6. if (href[0] === '#') {
  7. scrollTo(href)
  8. window.history && history.pushState({}, name, href)
  9. return false
  10. }
  11. })
  12. function scrollTo (hash) {
  13. var name = hash.substring(1)
  14. var target = $('a[name="' + name + '"]')
  15. if (target.length) {
  16. $('html, body').animate({ scrollTop: target.offset().top }
  17. , { duration: 500, easing: 'swing'})
  18. } else {
  19. console.log('documentation not written: %s', name)
  20. }
  21. return target
  22. }