Skip to content

Instantly share code, notes, and snippets.

@mpasteris
Created January 26, 2020 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpasteris/c422a675bcf4d5840bb9f5d4789912fa to your computer and use it in GitHub Desktop.
Save mpasteris/c422a675bcf4d5840bb9f5d4789912fa to your computer and use it in GitHub Desktop.
GSAP basic repeat and onRepeat
<link href='https://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Signika' rel='stylesheet' type='text/css'>
<div id="demo">
<div class="box green" id="greenBox">0</div>
</div>
//basic illustration of TweenMax's repeat, repeatDelay, yoyo and onRepeat
var box = document.getElementById("greenBox"),
count = 0,
tween;
tween = gsap.to(box, {duration: 2, left:"700px", repeat:10, yoyo:true, onRepeat:onRepeat, repeatDelay:0.5, ease:"none"});
function onRepeat() {
count++;
box.innerHTML = count;
gsap.set(box, {backgroundColor:"hsl(" + Math.random() * 255 + ", 90%, 60%)"});
}
<script src="https://cdn.jsdelivr.net/npm/gsap@3.0.1/dist/gsap.min.js"></script>
body {
background-color:#1d1d1d;
font-family: "Asap", sans-serif;
color:#989898;
margin:10px;
font-size:16px;
}
#demo {
height:100%;
position:relative;
overflow:hidden;
}
.box {
width:100px;
height:100px;
position:relative;
border-radius:6px;
margin-top:4px;
text-align:center;
line-height:100px;
color:black;
font-size:80px;
}
.green{
background-color:#6fb936;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment