Skip to content

Instantly share code, notes, and snippets.

@Animesh-Ghosh
Created August 23, 2020 09:00
Show Gist options
  • Select an option

  • Save Animesh-Ghosh/66eeaf949f240767372426dd0de02b4d to your computer and use it in GitHub Desktop.

Select an option

Save Animesh-Ghosh/66eeaf949f240767372426dd0de02b4d to your computer and use it in GitHub Desktop.
Animated SVG
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Animated SVG!</title>
<style type="text/css">
*, ::before, ::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #eee;
}
main {
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
min-height: 100vh;
}
svg {
max-width: 300px;
height: 300px;
}
</style>
</head>
<body>
<main>
<h1>Hi visitor!</h1>
<svg version="1.1" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg">
<g id="wave">
<path id="arm" d="m7.9375 7.9375c0.70556 0.35278 1.4114 0.70571 2.0727 0.52924 0.6613-0.17646 1.2787-0.882 1.896-1.5876" style="fill:none;stroke-width:.26458px;stroke:#000"/>
<ellipse id="hand" cx="12.055" cy="6.3423" rx=".55427" ry=".55427" style="fill:#fff;stroke-width:.21438;stroke:#000"/>
</g>
<g id="creature">
<ellipse id="face" cx="5.2917" cy="5.2917" rx="3.8407" ry="3.8407" style="fill:#faa;stroke-width:.25605;stroke:#000"/>
<g id="eyes">
<ellipse id="left-eye" cx="3.9688" cy="3.9688" rx=".52145" ry=".52145" style="fill:#0f0;stroke-width:.28002;stroke:#000"/>
<ellipse id="right-eye" cx="5.9531" cy="3.9688" rx=".52145" ry=".52145" style="fill:#0f0;stroke-width:.28002;stroke:#000"/>
</g>
<path id="mouth" d="m3.7783 6.4615c0.45272 0.42188 0.90522 0.84356 1.3655 0.83819 0.46032-0.00537 0.92868-0.43758 1.3971-0.86981" style="fill:none;stroke-width:.21735px;stroke:#000"/>
</g>
</svg>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.0/gsap.min.js"></script>
<script type="text/javascript">
const pathTo = 'm7.9375 7.9375c0.70556 0.35278 1.4114 0.70571 2.0727 0.35288 0.66129-0.35282 1.2786-1.4111 1.896-2.4696'
gsap.to('#arm', {
attr: {
d: pathTo
},
yoyo: true,
repeat: -1
})
gsap.to('#hand', {
attr: {
cy: '5.3423'
},
yoyo: true,
repeat: -1
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment