Created
November 15, 2012 00:45
-
-
Save fujikky/4075894 to your computer and use it in GitHub Desktop.
scroll timer
This file contains 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> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<title>$title</title> | |
$styles | |
</head> | |
<body> | |
<h1>$title</h1> | |
<p>hello</p> | |
<div id="log">log</div> | |
$scripts | |
</body> | |
</html> |
This file contains 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
var timer; | |
function getY() { | |
return scrollY + innerHeight - 21; | |
} | |
function handleScroll() { | |
var log = document.getElementById('log'); | |
var y = getY(); | |
log.innerHTML = y; | |
if (y >= 2000) { | |
timer = setTimeout(scrollEnd, 500); | |
} else { | |
clearTimeout(timer); | |
} | |
} | |
function scrollEnd() { | |
var y = getY(); | |
if (y >= 2000) { | |
document.body.style.background = 'red'; | |
setTimeout(function () { | |
scrollTo(0, 0); | |
document.body.style.background = ''; | |
}, 500); | |
} | |
} | |
window.addEventListener('scroll',handleScroll, false); | |
handleScroll(); |
This file contains 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
body { | |
background: #eee; | |
height: 2000px; | |
margin: 0; | |
padding: 0; | |
} | |
#log { | |
position: fixed; | |
bottom: 20px; | |
left: 10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment