Skip to content

Instantly share code, notes, and snippets.

@0xch4z
Created October 10, 2017 17:03
Show Gist options
  • Select an option

  • Save 0xch4z/819ab2e5c68a8e66554e494c4b0d664b to your computer and use it in GitHub Desktop.

Select an option

Save 0xch4z/819ab2e5c68a8e66554e494c4b0d664b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="wrapper">
<h1 id="message">
You're 0px from the top.
</h1>
</div>
<style>
@import url('https://fonts.googleapis.com/css?family=Quicksand');
* {
margin: 0;
padding: 0;
text-align: center;
font-family: 'Quicksand', Helvetica, Arial, sans-serif;
}
#wrapper {
height: 200vh;
background: #9e0;
}
h1 {
color: #fff;
position: fixed;
top: 125px;
width: 100%;
}
</style>
<script>
const msg = document.getElementById('message');
// function is called everytime the browser emits
// a `scroll` event
window.onscroll = function(event) {
msg.innerText = 'You\'re ' + document.body.scrollTop + 'px from the top';
console.log('you\'re scrolling!');
console.log('event: ', event);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment