首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >只有当我用vivus.js到达底部时,我的svg动画才会启动

只有当我用vivus.js到达底部时,我的svg动画才会启动
EN

Stack Overflow用户
提问于 2016-03-02 21:41:10
回答 1查看 1.8K关注 0票数 0

以下是我的问题:

我有一个很高的svg (1220 in高度,设置在viewbox中)。

如下所示:

代码语言:javascript
复制
<svg version="1.1" id="one-diagonal" viewBox="0 0 1160 1220" >
<g>
  <style type="text/css">
 .st1{fill:none;stroke:#939598;stroke-width:1;stroke-miterlimit:10;}
 </style>
 <defs>
</defs>
<line id="XMLID_64489_" class="st1" x1="710" y1="1" x2="0" y2="1212.9"/>
</svg>

我正在使用vivus来动画我的svg:

代码语言:javascript
复制
  function easeOutBounce (x) {
    var base = -Math.cos(x * (0.5 * Math.PI)) + 1;
    var rate = Math.pow(base,1.5);
    var rateR = Math.pow(1 - x, 2);
    var progress = -Math.abs(Math.cos(rate * (2.5 * Math.PI) )) + 1;
    return (1- rateR) + (progress * rateR);
  }

  var timing,
    timingProps = {
      type: 'delayed',
      duration: 150,
      start: 'autostart',
      pathTimingFunction: Vivus.LINEAR,
      animTimingFunction: Vivus.LINEAR
    };

  function timingTest (buttonEl, property, type) {
    var activeSibling = buttonEl.parentNode.querySelector('button.active');
    activeSibling.classList.remove('active');
    buttonEl.classList.add('active');

    timingProps.type = (property === 'type') ? type : timingProps.type;
    timingProps.pathTimingFunction = (property === 'path') ? Vivus[type] : timingProps.pathTimingFunction;
    timingProps.animTimingFunction = (property === 'anim') ? Vivus[type] : timingProps.animTimingFunction;

    timing && timing.stop().destroy();
    timing = new Vivus('timing-example', timingProps);
  }


    pola = new Vivus('one-diagonal', {type: 'delayed', duration: 50, forceRender: true, animTimingFunction: Vivus.EASE

});

我遇到的问题是,当viewbox设置为1220 at高度时,只有当我到达svg底部时,动画才会启动!

在这里可以看到一个活生生的例子:http://codepen.io/anon/pen/GZJvLm

我可以使用viewport在vivus.js脚本中看到代码,但如果我四处游玩(如果这更清楚的话呢?)

代码语言:javascript
复制
    /**
    * Reply if an element is in the page viewport
    *
    * @param  {object} el Element to observe
   * @param  {number} h  Percentage of height
  * @return {boolean}
  */
 Vivus.prototype.isInViewport = function (el, h) {
var scrolled   = this.scrollY(),
viewed       = scrolled + this.getViewportH(),
elBCR        = el.getBoundingClientRect(),
elHeight     = elBCR.height,
elTop        = scrolled + elBCR.top,
elBottom     = elTop + elHeight;

// if 0, the element is considered in the viewport as soon as it enters.
// if 1, the element is considered in the viewport only when it's fully inside
// value in percentage (1 >= h >= 0)
h = h || 0;

return (elTop + elHeight * h) <= viewed && (elBottom) >= scrolled;
};

/**
* Alias for document element
*
* @type {DOMelement}
*/
Vivus.prototype.docElem = window.document.documentElement;

/**
* Get the viewport height in pixels
*
* @return {integer} Viewport height
*/
Vivus.prototype.getViewportH = function () {
var client = this.docElem.clientHeight,
inner = window.innerHeight;

if (client < inner) {
return inner;
}
else {
return client;
}
};

  /**
* Get the page Y offset
*
* @return {integer} Page Y offset
*/
 Vivus.prototype.scrollY = function () {
return window.pageYOffset || this.docElem.scrollTop;
};

它都是白色的,但如果你滚动在底部,你会看到比svg出现和启动动画。

当我在svg顶部滚动视图时,有什么方法可以让动画开始--比如说100像素?或者就在它出现的时候?

谢谢你的帮助,我对此感到头痛,任何高脚杯都会令人惊奇:)

EN

回答 1

Stack Overflow用户

发布于 2016-04-16 17:46:26

“如果您需要编辑这个对象,可以在onReady回调中访问它”

https://github.com/maxwellito/vivus

onReady: function(myVivus) { // Then call myVivus.play(3); }

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

https://stackoverflow.com/questions/35758655

复制
相关文章

相似问题

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