Skip to content

Instantly share code, notes, and snippets.

@gucheen
Created March 4, 2015 12:49
Show Gist options
  • Save gucheen/aa96f0d6f63633117b1d to your computer and use it in GitHub Desktop.
Save gucheen/aa96f0d6f63633117b1d to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/wecovo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
body {
height: 3000px;
}
.scroll {
background: green;
width: 200px;
height: 300px;
overflow-y: scroll;
}
.content {
height: 800px;
}
</style>
</head>
<body>
<div class="scroll">
<div class="content"></div>
</div>
<script id="jsbin-javascript">
var scroll = document.getElementsByClassName('scroll')[0];
var content = document.getElementsByClassName('content')[0];
function handleScroll (e) {
if (e.deltaY < 0 && scroll.scrollTop === 0) {
e.preventDefault();
}
if (e.deltaY > 0 && (scroll.scrollTop + scroll.offsetHeight) >= scroll.scrollHeight) {
e.preventDefault();
}
}
scroll.addEventListener('mousewheel', handleScroll);
</script>
<script id="jsbin-source-css" type="text/css">body {
height: 3000px;
}
.scroll {
background: green;
width: 200px;
height: 300px;
overflow-y: scroll;
}
.content {
height: 800px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var scroll = document.getElementsByClassName('scroll')[0];
var content = document.getElementsByClassName('content')[0];
function handleScroll (e) {
if (e.deltaY < 0 && scroll.scrollTop === 0) {
e.preventDefault();
}
if (e.deltaY > 0 && (scroll.scrollTop + scroll.offsetHeight) >= scroll.scrollHeight) {
e.preventDefault();
}
}
scroll.addEventListener('mousewheel', handleScroll);</script></body>
</html>
body {
height: 3000px;
}
.scroll {
background: green;
width: 200px;
height: 300px;
overflow-y: scroll;
}
.content {
height: 800px;
}
var scroll = document.getElementsByClassName('scroll')[0];
var content = document.getElementsByClassName('content')[0];
function handleScroll (e) {
if (e.deltaY < 0 && scroll.scrollTop === 0) {
e.preventDefault();
}
if (e.deltaY > 0 && (scroll.scrollTop + scroll.offsetHeight) >= scroll.scrollHeight) {
e.preventDefault();
}
}
scroll.addEventListener('mousewheel', handleScroll);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment