Skip to content

Instantly share code, notes, and snippets.

@tholman
Created February 28, 2015 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tholman/2f7fe40347d8e5fb03f3 to your computer and use it in GitHub Desktop.
Save tholman/2f7fe40347d8e5fb03f3 to your computer and use it in GitHub Desktop.
<!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