Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/10238e75bdfbc1a02bac to your computer and use it in GitHub Desktop.
Save anonymous/10238e75bdfbc1a02bac to your computer and use it in GitHub Desktop.
Knockout text with animated background
<div class="wrap">
<div class="clip-text clip-text_one">in the jungle, the mighty jungle, the lion sleeps tonight.</div>
</div>
var tl = new TimelineMax({repeat:-1, yoyo:true});
tl.to(".clip-text", 4, { css:{"background-position": "800px"} , ease:Quad.easeInOut });
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js"></script>
@import url(http://fonts.googleapis.com/css?family=Oswald:400,700);
body {
font-family: 'Oswald', sans-serif;
color: #000;
background-color: #fff;
}
.wrap {
max-width: 50%;
margin: 0 auto;
}
/* Clip text element */
.clip-text {
font-size: 6em;
font-weight: bold;
line-height: 1;
position: relative;
display: inline-block;
margin: .25em;
padding: .5em .75em;
text-align: center;
/* Color fallback */
color: #000;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-fill-color: transparent;
}
.clip-text:before,
.clip-text:after {
position: absolute;
content: '';
}
/* Background */
.clip-text:before {
z-index: -2;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: inherit;
}
/* Text outer background */
.clip-text:after {
position: absolute;
z-index: -1;
top: 0em;
right: 0em;
bottom: 0em;
left: 0em;
background-color: #fff;
}
.clip-text_one {
background-image: url(http://i.imgur.com/pJewmf8.jpg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment