Skip to content

Instantly share code, notes, and snippets.

@pauginer
Last active October 10, 2020 15:12
Show Gist options
  • Save pauginer/899f947df1987f148775 to your computer and use it in GitHub Desktop.
Save pauginer/899f947df1987f148775 to your computer and use it in GitHub Desktop.
Add this to the header of a Hype document to be able to move through scenes by using the keyboard arrows which may be convenient for creating presentations with Hype.
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
// http://mikemurko.com/general/jquery-keycode-cheatsheet/
var speed = 0.8; //transition speed
var transition = "push"; //types of transition: instant, fade, swap, push
var nextKeys= [39, 40, 34];
var prevKeys= [37, 38, 33];
$(function(){
$( "body" ).keyup(function(e){
var hypeDocument = getHypeDocument();
var t = transitionType(hypeDocument, transition);
if($.inArray(e.which, nextKeys) > -1){
hypeDocument.showNextScene(t[0], speed);
}else if ($.inArray(e.which, prevKeys) > -1){
hypeDocument.showPreviousScene(t[1], speed)
}
});
});
function transitionType(hypeDocument,type){
var result = [hypeDocument.kSceneTransitionInstant, hypeDocument.kSceneTransitionInstant];
if(type == "fade"){
result = [hypeDocument.kSceneTransitionCrossfade, hypeDocument.kSceneTransitionCrossfade];
} else if (type == "swap") {
result = [hypeDocument.kSceneTransitionSwap, hypeDocument.kSceneTransitionSwap];
} else if (type = "push") {
result = [hypeDocument.kSceneTransitionPushRightToLeft, hypeDocument.kSceneTransitionPushLeftToRight];
}
return result;
}
function getHypeDocument(){
var name = "index";
for(var key in HYPE.documents){
name = key;
}
return HYPE.documents[name];
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment