Skip to content

Instantly share code, notes, and snippets.

@kuoe0
Created August 16, 2013 16:08
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 kuoe0/6251206 to your computer and use it in GitHub Desktop.
Save kuoe0/6251206 to your computer and use it in GitHub Desktop.
<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