首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当动画可见时,我如何启动它?

当动画可见时,我如何启动它?
EN

Stack Overflow用户
提问于 2019-08-26 11:42:13
回答 1查看 614关注 0票数 0

代码语言:javascript
运行
复制
.responsive {
  width:200px;
  float:left;
  margin-top: 750px;
  margin-bottom: 750px;
}

.st0 {
  fill: #ffffff;
}

.st1 {
  fill: none;
  stroke: #afafaf;
  stroke-width: 4;
  stroke-miterlimit: 10;
}

.st2 {
  fill: #ffffff;
  stroke: #afafaf;
  stroke-width: 4;
  stroke-miterlimit: 10;
}

.st3 {
  fill: none;
  stroke: #2646ff;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-miterlimit: 10;
}

#responsive .st3 {
  stroke-dasharray: 1932;
  stroke-dashoffset: 0;
  animation: responsive 4s ease-in-out 0s;
  animation-direction: reverse;
}
@keyframes responsive {
  to {
    stroke-dashoffset: 1932;
  }
}
代码语言:javascript
运行
复制
<div class="responsive">

<svg
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          x="0px"
          y="0px"
          viewBox="0 0 1200 780"
          style="enable-background:new 0 0 1200 780;"
          xml:space="preserve"
        >
          <g id="Layer_1"></g>
          <g id="Layer_6">
            <g>
              <g>
                <path
                  class="st0"
                  d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
                />
                <path
                  class="st1"
                  d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
                />
              </g>
              <line class="st1" x1="2" y1="688.2" x2="1198" y2="688.2" />
              <ellipse class="st2" cx="559.9" cy="732.7" rx="16.9" ry="16.7" />
            </g>
          </g>
          <g id="Layer_5">
            <g>
              <g>
                <path
                  class="st0"
                  d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
                />
                <path
                  class="st1"
                  d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
                />
              </g>
              <line class="st1" x1="626.5" y1="715.5" x2="1127.3" y2="715.5" />
            </g>
          </g>
          <g id="Layer_4">
            <g>
              <g>
                <path
                  class="st0"
                  d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
                />
                <path
                  class="st1"
                  d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
                />
              </g>
              <line class="st1" x1="971.8" y1="732" x2="1198" y2="732" />
            </g>
          </g>
          <g id="responsive">
            <g>
              <path
                class="st3"
                d="M2,35.9L2,772.2 C2,775 4.2,777.2 7,777.2 L1194.1,777.2"
              />
            </g>
          </g>
        </svg>
        
        
        </div>

在片段中向下滚动以查看svg +动画.

当svg (动画)在视图中时,我想启动这个动画。我该怎么做?我遇到了很多javascript代码,但问题是,不同类型的类都太复杂了。我只是想先启动动画一次,然后将它保持在结束状态(所以不要循环或其他什么)。

我给了部分.responsive一些边缘顶部和底部,通常在白色区域之间有内容。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-26 12:02:46

如果您想要一个简单的解决方案,然后是WOW.js是您的选择:)步骤为您的svg添加动画:

  1. 如插件文档中所述,安装wow.js。
  2. wow类名添加到动画包装器中,然后在

代码语言:javascript
运行
复制
.animated #responsive .st3 {
  stroke-dasharray: 1932;
  stroke-dashoffset: 0;
  animation: responsive 4s ease-in-out 0s;
  animation-direction: reverse;
}

  1. 这是您的wow.js init应该是什么样的示例:)

代码语言:javascript
运行
复制
wow = new WOW(
  {
  boxClass:     'wow',      // add this className to animation wrapper
  animateClass: 'animated', // class added by lib, when your item are in view
  offset:       0,          // number of px before item appear on screen and animation starts
  mobile:       true,       // default
  live:         true        // `true` if you add items on page dynamically
}
)
wow.init();

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57657278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档