Created
February 28, 2015 23:06
-
-
Save tholman/2f7fe40347d8e5fb03f3 to your computer and use it in GitHub Desktop.
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
<!doctype html> | |
<html> | |
<head> | |
<title>Scroll position demo</title> | |
<style> | |
html, body { | |
margin: 0px; | |
padding: 0px; | |
min-height: 100%; | |
} | |
body { | |
height: 200%; | |
} | |
h1 { | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
transform: translateX(-50%) translateY(-50%); | |
font-family: impact; | |
font-size: 160px; | |
margin: 0px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>0</h1> | |
<script> | |
var element = document.querySelector('h1'); | |
window.addEventListener("scroll", function() { | |
scrollPosition = window.pageYOffset || document.body.scrollTop; | |
element.innerHTML = scrollPosition; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment