Last active
December 23, 2015 13:49
-
-
Save groteck/6644331 to your computer and use it in GitHub Desktop.
Example of terminal emulator
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
%html | |
%body | |
%code | |
%span.cursor | |
| |
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
$.fn.typer = function (text, options) { | |
options = $.extend({}, { | |
delay: 1000, | |
duration: 1000, | |
easing: 'linear', | |
endless: false | |
}, options); | |
var elem = $(this); | |
(function loop(i) { | |
var e = typeof text === 'string' ? text : text[i]; | |
// strip html tags, might be helpful | |
// e.replace(/(<.*?>)/ig,"") | |
$({len: 0}).delay(options.delay).animate({len: e.length}, { | |
duration: options.duration, | |
easing: options.easing, | |
step: function (now) { | |
var pos = Math.ceil(now), | |
char = e.substr(pos, 0); | |
elem.html(e.substr(0, pos)); | |
}, | |
complete: function () { | |
i++; | |
if (i === text.length && !options.endless) { | |
return; | |
} else if (i === text.length) { | |
i = 0; | |
} | |
loop(i); | |
} | |
}); | |
})(0); | |
}; | |
$('code').typer(["$ touch file.txt <br/> $ cat \"this is a test\" > file.txt" ]); |
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
.cursor { | |
-moz-animation: cursorAnimation 0.5s infinite; /* Firefox */ | |
-webkit-animation: cursorAnimation 0.5s infinite; /* Safari and Chrome */ | |
} | |
code { | |
} | |
@-moz-keyframes cursorAnimation { | |
0% {opacity: 0;} | |
100% {opacity: 1;} | |
} | |
@-webkit-keyframes cursorAnimation { | |
0% {opacity: 0;} | |
100% {opacity: 1;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment