bookmark.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. window.addEventListener('DOMContentLoaded', function () {
  3. function n() {
  4. localStorage.setItem('bookmark' + location.pathname, window.scrollY);
  5. }
  6. function e() {
  7. var n = localStorage.getItem('bookmark' + location.pathname);
  8. n = parseInt(n, 10), isNaN(n) || '' !== location.hash || window.anime({
  9. targets: document.scrollingElement,
  10. duration: 200,
  11. easing: 'linear',
  12. scrollTop: n
  13. });
  14. }
  15. var o, t;
  16. o = CONFIG.bookmark.save, t = document.querySelector('.book-mark-link'), window.addEventListener('scroll', function () {
  17. return t.classList.toggle('book-mark-link-fixed', 0 === window.scrollY);
  18. }), 'auto' === o && (window.addEventListener('beforeunload', n), window.addEventListener('pjax:send', n)), t.addEventListener('click', function () {
  19. n(), window.anime({
  20. targets: t,
  21. duration: 200,
  22. easing: 'linear',
  23. top: -30,
  24. complete: function () {
  25. setTimeout(function () {
  26. t.style.top = '';
  27. }, 400);
  28. }
  29. });
  30. }), e(), window.addEventListener('pjax:success', e);
  31. });