gsap+svg实现行走的小人开关动画效果代码

代码语言:html

所属分类:其他

代码描述:gsap+svg实现行走的小人开关动画效果代码,结合了GSDevTools3及DrawSVGPlugin3等插件一同实现。

代码标签: gsap svg 行走 小人 开关 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700,800,900&display=swap" rel="stylesheet">

  
  
<style>
:root {
  --clr-0: #CCCCCC;
 --clr-1: #f5f5f5;
 --clr-2: #232323;
}
body {
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  background-color: var(--clr-0);
}
/* body.light {
  background-color: var(--clr-0);
} */
body.light .cover{
  background-color: var(--clr-0);
}
#stick-figure-svg {
  opacity: 0;
  visibility: hidden;
}
body.light .theme-toggle-button {
  border-color: white;
  background-color: var(--clr-0);
}
/* body.dark {
  background-color:  var(--clr-2);
} */
body.dark .cover {
  background-color:  var(--clr-2);
}
body.dark .theme-toggle-button {
  border-color: #b8b1a7;
  background-color: var(--clr-2);
}
body.dark #R-leg, body.dark #L-leg {
  stroke: white;
}
body.light #R-leg, body.light #L-leg {
  stroke: #232323;
}
.cover {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 75px;
  height: 75px;
  background-color: black;
  z-index: -1;
}
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  flex-direction: column;
  gap: 2rem;
  position: relative;
  overflow: hidden;
}
button {
  padding: 2rem;
  cursor: pointer;
}
.theme-toggle-button {
    width: 15rem;
    height: 5rem;
    border: 4px solid white;
    border-radius: 50px;
    display: flex;
    align-items: flex-end;
    padding: 0;
    background-color: var(--clr-0);
}
#stick-figure-svg {
  width: 147%;
  height: 147%;
/*   border: 1px solid; */
}

.template-footer {
  position: fixed;
  bottom: 0;
  right: 0; 
  height: 2rem;
  width: 15rem;
  border-radius: 5px 0 0 0;
  background-color: #ffffba;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.6rem;
}
</style>


</head>

<body>
  <div class="container">
  <div class="cover"></div>
  <button type="submit" class="theme-toggle-button">
     <svg width="100%" id="stick-figure-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 150 200">
      <defs>
        <linearGradient id="linear-gradient" x1="27.6" y1="49.33" x2="125.11" y2="135.42" gradientTransform="matrix(1, 0, 0, 1, 0, 0)" gradientUnits="userSpaceOnUse">
          <stop offset="0" stop-color="#f0b402" />
          <stop offset=".26" stop-color="#f1a508" />
          <stop offset=".69" stop-color="#f39210" />
          <stop offset=".99" stop-color="#f48c13" />
        </linearGradient>
        <mask id="faceClip">
          <circle id="face-clip" cx="58" cy="142" r="57"></circle>
        </mask>
      </defs>
       <g id="stick-figure">
      <g id="R-leg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" >
        <line id="R-thigh" x1="70" y1="168" x2="70" y2="138" />
        <line id="R-calf" x1="70" y1="168" x2="70" y2="198" />
        <line id="R-foot" x1="70" y1="198" x2="82" y2="198" />
      </g>
      <g id="L-leg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" >
        <line id="L-thigh" x1="46" y1="168" x2="46" y2="138"  />
        <line id="L-calf" x1="46" y1="168" x2="46" y2="198"  />
        <line id="L-foot" x1="46" y1="198" x2="34" y2="198"  />
      </g>
<!--       <circle id="face" cx="75" cy="91.18" r="60" fill="url(#linear-gradient)" /> -->
    <circle id="face" cx="58" cy="132" r="68" fill="url(#linear-gradient)" ></circle>
  <g id="eyes-mouth" >
        <circle id="L-eye" cx="57.68" cy="83.18" r="3.5" />
        <circle id="R-eye" cx="90.68" cy="83.18" r="3.5" />
        <path id="mouth" d="M79.53,91.98c.15,0,.25,.22,.22,.45-.27,2-2.29,3.55-4.74,3.55s-4.48-1.55-4.74-3.55c-.03-.23,.07-.45,.22-.45h9.05Z" fill="#fff" transform-origin="center" transform="scale(1.3)"/>
      </g>
	<g id="highlights" stroke="white" fill="none"  stroke-linecap="round"
			stroke-linejoin="round" stroke-width="2" >
		<path id="hl-1" d="M76.06,145.54l-13.33-13.33"  />
		<path id="hl-2" d="M92.73,132.21l-13.33,13.33"  />
		<path id="hl-3" d="M63.63,161.31l13.33-13.33"  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0