This is my solution.
I'll load (subload) the css file later and therefore also the images.
Only the HTML and JS Files are initial Load.
<script>
const csshref = "./css/style.css";
document.addEventListener("DOMContentLoaded", function(event) {
window.setTimeout(function() {
const headElement = document.getElementsByTagName('head')[0];
const cssElement = document.createElement('link');
cssElement.rel = 'stylesheet';
cssElement.href = csshref;
headElement.appendChild(cssElement);
}, 1000 /* 1 second delay */ );
});
</script>
I also switched to GSAP3 and replaced the TweenMax. The only problem I have now is the loop.
How do I adapt TweenMax.killAll(); to GSAP3?
function byID(a){
return document.getElementById(a);
}
function initAnimation() {
tl = gsap.timeline({repeat:-1, paused:true});
tl.set('#banner', {display: "block"}, 0);
tl.set(['#txt1','#txt2'], {backgroundPosition:'0px 0px', opacity:0}, 0);
tl.add([
gsap.to('#txt1',{duration:.6, backgroundPosition:'0px 0px', opacity:1,delay:.2}),
gsap.to('#txt2',{duration:.6, backgroundPosition:'0px 0px', opacity:1,delay:.5}),
],"+=1");
tl.call(cnc, null, this, "+=0");
tl.add([
gsap.to('#txt1',{duration:.5, opacity:0}),
gsap.to('#txt2',{duration:.5, opacity:0}),
],"+=5");
tl.play();
//console.log(tl.duration());
}
function cnc() {
cnt--;
tl.pause();
if(cnt > 0) {
tl.resume();
}else{
gsap.killTweensOf();
}
}
var ad = byID('#banner'),
cta_wrapper = byID('cta_wrapper'),
cnt = 2,
tl,
b = {a:0};;
window.onload = initAnimation;