kuoe0
8/16/2013 - 4:08 PM

From http://blog.tonycube.com/2013/07/j-k.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+blogspot%2FYJzd+%28Tony%27s+Blog%2

<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>