A simple example of animated typing, as used in a couple of places in the Stitch Fix Algorithms Tour.
Animated Typing
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
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<body> | |
<svg width="960" height="500"> | |
<text transform="translate(150 250)" font-size="18px"></text> | |
</svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
function stylist_note_typing_animation(progress){ | |
var text_val = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ..." | |
var text_progress = Math.max(0, | |
Math.min( text_val.length + 1, | |
Math.floor(progress * text_val.length))) | |
d3.select("svg").select("text") | |
.text(text_val.substring(0, text_progress)) | |
} | |
var progress = 0 | |
d3.interval(function(){ | |
var r = Math.random() | |
if (r < 0.8) { | |
if ((r < 0.1) && (progress > 0.2)) { | |
progress -= 0.01 | |
} else { | |
progress += 0.01 | |
} | |
stylist_note_typing_animation(progress) | |
} | |
}, 50) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment