- commit
- 6e6c7af5e3d08c36ff4d03bc6ff240759071046a
- parent
- a59019b33f658cbb8bb24cc992c4109018433db7
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2016-11-18 18:13
refactor
Diffstat
| M | smooth-scroll.js | 15 | +++++++-------- |
1 files changed, 7 insertions, 8 deletions
diff --git a/smooth-scroll.js b/smooth-scroll.js
@@ -41,23 +41,22 @@ 41 41 }; 42 42 43 43 var init = function() { -1 44 var scroll = function(selector) { -1 45 var scrollY = document.querySelector(selector).offsetTop; -1 46 smoothScrollTo(scrollY); -1 47 }; -1 48 44 49 var smoothScrollClick = function(event) { 45 50 event.preventDefault(); 46 51 47 52 var selector = event.currentTarget.getAttribute('href');48 -1 var scrollY = document.querySelector(selector).offsetTop;49 -150 53 history.pushState(null, null, selector);51 -1 smoothScrollTo(scrollY);-1 54 scroll(selector); 52 55 }; 53 56 54 57 window.addEventListener('popstate', function(event) { 55 58 event.preventDefault();56 -157 -1 var selector = window.location.hash;58 -1 var scrollY = document.querySelector(selector).offsetTop;59 -160 -1 smoothScrollTo(scrollY);-1 59 scroll(window.location.hash); 61 60 }); 62 61 63 62 var links = document.querySelectorAll('[href^="#"]');