Last active
March 25, 2018 22:30
-
-
Save stretchkennedy/1541d60e10fd900340cafed00370d456 to your computer and use it in GitHub Desktop.
persist turbolinks position in vanilla js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Turbolinks.scroll = {} | |
document.addEventListener('click', function(e) { | |
var el = e.target; | |
if (el.getAttribute('data-turbolinks-scroll') !== 'false') return; | |
Turbolinks.scroll.top = window.scrollY || document.documentElement.scrollTop || document.documentElement.scrollTop; | |
}); | |
document.addEventListener('turbolinks:load', function() { | |
if (Turbolinks.scroll.top) { | |
window.scrollY = document.documentElement.scrollTop = document.body.scrollTop = Turbolinks.scroll.top; | |
} | |
Turbolinks.scroll = {}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment