Timeline Control on pressing buttons

 Tween Control on pressing buttons


It is also exactly same like of tween control, as;


let myTimeAnimation = gsap.timeline()
    .to(".box1", {x:400, duration:2})
    .to(".box2", {x:400, duration:2})
    .to(".box3", {x:400, duration:2})

window.onload = ()=>{
    myTimeAnimation.pause()
}

document.querySelector(".start").onclick =()=>{
    myTimeAnimation.play()
}
document.querySelector(".pause").onclick =()=>{
    myTimeAnimation.pause()
}
document.querySelector(".restart").onclick =()=>{
    myTimeAnimation.restart()
}
document.querySelector(".reverse").onclick =()=>{
    myTimeAnimation.reverse()
}



window.onload will keep animation stopped at the beginning, previously in tween there was single box so we can set  paused:"true",   inside that box property, but in timeline there may be many items, and it may not possible to set value for every items, so directly using window.onload,
this will works on tween also as same like this;

You can also add labels in your timeline so that you can directly jump into specific point in timeline by skipping other, just you can put:

.from("#freds img", {y:160, duration:0.8, ease:"back"}, "+=0.5")
.add("test")
.from("#time", {xPercent:100, duration:1, ease:"bounce"});

now you can directly jump into #time's timeline, 
The things that comes after the .add are played and other are skipped



All codes together

HTML





















CSS






Javascript






Comments

Popular posts from this blog

CSS simple grid layout

Gsap timeline position parameters

GSAP Timelines