Last active
August 29, 2015 14:26
-
-
Save RegisBiron/169c33746f93d6e8aadb to your computer and use it in GitHub Desktop.
Video Capture Page Scroller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In order to use this script add the class '.scroll-item' to the item you wish to scroll to. | |
// You'll need to choose elTop, elCenter, or elBottom depending on where you want to scroll in relation to the item's position. | |
// Feel free to modify this gist and improve upon it. | |
$(document).ready(function() { | |
"use strict"; | |
var windowHeight = $(window).height(), | |
scrollAmount = 0, | |
scrollDuration = 0, | |
scrollItems = [], | |
scrollIndex = 0, | |
sEasing = 600; | |
// Query/Bind scroll elements here | |
var $scrollItem = $('.scroll-item'); | |
$(window).resize(function(event) { | |
windowHeight = $(window).height(); | |
}); | |
$scrollItem.each(function() { | |
scrollItems.push( | |
{ | |
elTop: $(this).offset().top, | |
elCenter: $(this).offset().top - ($(this).height() / 2), | |
elBottom: $(this).offset().top + $(this).height() | |
} | |
); | |
}); | |
function scrollPage(event, scrollPos) { | |
if(event.keyCode === 86) { | |
// scroll down | |
scrollAmount = scrollItems[scrollIndex].elTop; | |
scrollIndex += 1; | |
} else if(event.keyCode === 70) { | |
// scroll up | |
scrollIndex -= 1; | |
scrollAmount = scrollItems[scrollIndex - 1].elTop; | |
} else { | |
// scroll back to top | |
scrollAmount = 0; | |
scrollIndex = 0; | |
} | |
$('body, html').animate({ | |
scrollTop: scrollAmount, | |
easing: 'easeInOutCirc' | |
}, sEasing); | |
scrollAmount = 0; | |
} | |
$(document).keydown(function(e) { | |
switch(e.keyCode) { | |
case 86: | |
// v | |
// scrolls the page down | |
scrollPage(e); | |
break; | |
case 70: | |
// f | |
// scrolls the page up | |
scrollPage(e); | |
break; | |
case 88: | |
// x | |
// scrolls back to top | |
scrollPage(e); | |
break; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment