Created
August 16, 2013 16:08
-
-
Save kuoe0/6251206 to your computer and use it in GitHub Desktop.
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
<script type="text/javascript"> | |
var interval = 25; | |
var myTimer; | |
var isTick = false; | |
var h = getDocHeight() * 0.6; | |
//console.log(h); | |
var count = 0; | |
var time = 10; | |
var step = h / time; | |
function getDocHeight(){ | |
if (window.innerHeight != undefined) { | |
return window.innerHeight; | |
} | |
return 500; | |
} | |
function press(event){ | |
switch(event.keyCode){ | |
case 106: | |
// console.log("j"); | |
step = Math.abs(step); | |
startTimer(); | |
break; | |
case 107: | |
// console.log("k"); | |
step = (step > 0) ? -step : step; | |
startTimer(); | |
break; | |
} | |
//console.log(event.keyCode); | |
} | |
function scrollTo(){ | |
if (count < time) { | |
window.scrollBy(0, step); | |
count++; | |
}else{ | |
count = 0; | |
stopTimer(); | |
} | |
} | |
function startTimer() | |
{ | |
if (!isTick) { | |
isTick = true; | |
myTimer=setInterval(function(){tick()},interval); | |
}; | |
} | |
function tick(){ | |
// console.log("..."); | |
scrollTo(); | |
} | |
function stopTimer(){ | |
if (isTick) { | |
clearInterval(myTimer); | |
isTick = false; | |
}; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment