Emulate Spacebar Scroll Function
I'm developing a function which scrolls to every image, but when in text i'd like to emulate the spacebar function So the code I have is: window.scrollBy(0,window.innerHeight*0.8);
Solution 1:
window.scrollTo
will do that. You'll have to use the current scroll position + a set interval like
window.scrollTo(0, window.scrollY+=200)
I'm not sure what interval the space bar actually uses but I'm sure you can find a value you're happy with.
edit: window.pageYOffset might be more browser friendly. Here's the space bar emulated in your own code. Not sure why you'd want to:
document.onkeydown = function(event) {
if(event.keyCode===32){
event.preventDefault();
window.scrollTo(0, window.pageYOffset+=window.innerHeight*0.8)
}
}
Post a Comment for "Emulate Spacebar Scroll Function"