anya-ji's picture
Duplicate from anim2code/dataset
2086c64
Raw History Blame Contribute Delete
4.56 kB
<!DOCTYPE html>
<html>
<head>
<style>body {
background-color: #000;
overflow: hidden;
text-align:center;
display: flex;
align-items: center;
justify-content: center;
}
body,
html {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
svg {
width: 100%;
height: 100%;
visibility: hidden;
}</style>
<script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script>
</head>
<body>
<svg id="mainSVG" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600">
<defs>
<g id="blackBoxes">
<g id="boxes0">
<rect x="-98.79" y="41.34" width="100" height="100"/>
<rect x="42.63" y="41.34" width="100" height="100"/>
<rect x="184.05" y="41.34" width="100" height="100"/>
<rect x="325.47" y="41.34" width="100" height="100"/>
<rect x="466.9" y="41.34" width="100" height="100"/>
<rect x="608.32" y="41.34" width="100" height="100"/>
<rect x="749.74" y="41.34" width="100" height="100"/>
<rect x="891.16" y="41.34" width="100" height="100"/>
</g>
<g id="boxes1" transform="translate(0, 141.42)">
<rect x="42.63" y="41.34" width="100" height="100"/>
<rect x="184.05" y="41.34" width="100" height="100"/>
<rect x="325.47" y="41.34" width="100" height="100"/>
<rect x="466.9" y="41.34" width="100" height="100"/>
<rect x="608.32" y="41.34" width="100" height="100"/>
<rect x="749.74" y="41.34" width="100" height="100"/>
<rect x="891.16" y="41.34" width="100" height="100"/>
<rect x="1032.58" y="41.34" width="100" height="100"/>
</g>
</g>
<g id="whiteBoxes" >
<g id="boxes2">
<rect x="-98.79" y="41.34" width="100" height="100"/>
<rect x="42.63" y="41.34" width="100" height="100"/>
<rect x="184.05" y="41.34" width="100" height="100"/>
<rect x="325.47" y="41.34" width="100" height="100"/>
<rect x="466.9" y="41.34" width="100" height="100"/>
<rect x="608.32" y="41.34" width="100" height="100"/>
<rect x="749.74" y="41.34" width="100" height="100"/>
<rect x="891.16" y="41.34" width="100" height="100"/>
</g>
<g id="boxes3" transform="translate(0, 141.42)">
<rect x="42.63" y="41.34" width="100" height="100"/>
<rect x="184.05" y="41.34" width="100" height="100"/>
<rect x="325.47" y="41.34" width="100" height="100"/>
<rect x="466.9" y="41.34" width="100" height="100"/>
<rect x="608.32" y="41.34" width="100" height="100"/>
<rect x="749.74" y="41.34" width="100" height="100"/>
<rect x="891.16" y="41.34" width="100" height="100"/>
<rect x="1032.58" y="41.34" width="100" height="100"/>
</g>
</g>
<rect id="bg" width="100%" height="100%" />
<clipPath id="mainMask">
<circle cx="400" cy="300" r="200" />
</clipPath>
</defs>
<g clip-path="url(#mainMask)">
<use xlink:href="#bg" fill="#FFF" />
<g id="black">
<use xlink:href="#blackBoxes" />
<use xlink:href="#blackBoxes" y="282.84" />
</g>
<g id="white" opacity="0" fill="#FFF">
<use xlink:href="#whiteBoxes" x="-70.705" y="-70.705"/>
<use xlink:href="#whiteBoxes" x="-70.705" y="212.115" />
</g>
</g>
<circle cx="400" cy="300" r="200" fill="none" stroke="#000" stroke-width="5"/>
</svg>
<script>gsap.set('svg', {
visibility: 'visible'
})
gsap.set('rect', {
transformOrigin: '50% 50%'
})
let tl = gsap.timeline({
repeat: -1,
defaults: {
duration: 1
}
});
tl.set('#bg', {
fill: '#FFF'
})
.fromTo('#boxes0 rect', {
rotation: 45,
x: 141.42
},{
rotation: -45,
ease: 'power1.inOut',
x: 0
})
.fromTo('#boxes1 rect', {
rotation: -45,
x: -141.42
},{
rotation: 45,
ease: 'power2.inOut',
x: -0
}, 0)
.add('rev')
.set(['#black', '#white'], {
autoAlpha: gsap.utils.wrap([0, 1])
})
.set('#bg', {
fill: '#000'
})
.fromTo('#boxes2 rect', {
rotation: 45,
x: 141.42
},{
rotation: -45,
ease: 'sine.inOut',
x: 0
})
.fromTo('#boxes3 rect', {
rotation: -45,
x: -141.42
}, {
rotation: 45,
ease: 'power2.inOut',
x: -0
},'rev')
//ScrubGSAPTimeline(tl)</script>
</body>
</html>