Skip to content

Instantly share code, notes, and snippets.

@smohadjer smohadjer/scrollByPixel.md

Last active Apr 29, 2016
Embed
What would you like to do?
scroll by pixel using arrow keys

Scroll by one pixel via arrow keys up/down for finer control over scrolling. Use to debug scroll related issues.

$(window).on('keydown', function(event) {
	event.preventDefault();
	event.stopPropagation();
	
	var sctop = $(window).scrollTop();
	
	if (event.keyCode === 38) { //up arrow
		sctop--;
	} else if (event.keyCode === 40) { //down arrow
		sctop++;
	} else {
		return; //do nothing
	}
	
	$(window).scrollTop(sctop);
});
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.