JSFiddle - React, Tailwind, and code Playground
by rwhal06
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="test" class="fancy_title">
<canvas width=600 height=100></canvas>
</div>
SCSS
body {
background-color: #000;
}
#test {
position:absolute;
left:0;
right:0;
height:100px;
margin: 0 auto;
text-align:center;
width: 100%;
}
#test canvas {
margin:0 auto;
text-align:center;
}
@keyframes fadeInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-15px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
/* Firefox < 16 */
@-moz-keyframes fadeInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-15px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadeInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-15px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
/* Internet Explorer */
@-ms-keyframes fadeInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-15px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
/* Opera < 12.1 */
@-o-keyframes fadeInLeft {
0% {
opacity: 0;
-webkit-transform: translateX(-15px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
JavaScript
WebFontConfig = {
//google: { families: [ 'Loved+by+the+King::latin' ] }
google: { families: [ 'Cookie::latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
//$(".fancy_title p").lettering();
// get 2D context
var ctx = document.querySelector("canvas").getContext("2d"),
// dash-length for off-range
dashLen = 220,
// we'll update this, initialize
dashOffset = dashLen,
// some arbitrary speed
speed = 30,
// the text we will draw
txt = "“Prosperity of every kind is drawn to me.”",
// start position for x and iterator
x = 30, i = 0;
// Comic Sans?? Let's make it useful for something ;) w/ fallbacks
//ctx.font = "50px Loved by the King";
ctx.font = "50px Cookie";
// thickness of the line
ctx.lineWidth = 1;
// to avoid spikes we can join each line with a round joint
//ctx.lineJoin = "round";
// increase realism letting background (f.ex. paper) show through
ctx.globalAlpha = 2/3;
// some color, lets use a black pencil
ctx.strokeStyle = ctx.fillStyle = "#FFF";
(function loop() {
// clear canvas for each frame
ctx.clearRect(x, 0, 60, 150);
// calculate and set current line-dash for this char
ctx.setLineDash([dashLen - dashOffset, dashOffset - speed]);
// reduce length of off-dash
dashOffset -= speed;
// draw char to canvas with current dash-length
ctx.strokeText(txt[i], x, 90);
// char done? no, the loop
if (dashOffset > 0) requestAnimationFrame(loop);
else {
// ok, outline done, lets fill its interior before next
ctx.fillText(txt[i], x,...