Skip to content

Instantly share code, notes, and snippets.

@kuoe0 kuoe0/JK_to_move.js
Created Aug 16, 2013

Embed
What would you like to do?
<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
You can’t perform that action at this time.