[英]Reveal svg animation on scroll
I have an animated svg that comes just after a big header image (which takes up 100% of the viewport). 我有一个动画svg,它紧接在一个大标题图像之后(占据了视口的100%)。
http://jsfiddle.net/qx7p46f3/3/ http://jsfiddle.net/qx7p46f3/3/
The animation starts as soon as the page is loaded but I want to trigger it only when the users scrolls to that specific part of the page. 动画在页面加载后立即开始,但是我只想在用户滚动到页面的特定部分时才触发动画。
I know there are plugins like wow.js but, I don't know, it's optimized for animate.css
and I can't find a way to make it work with my code. 我知道有像wow.js这样的插件,但是我不知道,它已经针对animate.css
进行了优化,我找不到一种使其与我的代码一起工作的方法。
I'm stuck with scrollreveal as well. 我也坚持使用scrollreveal 。 I added the js code at the bottom of the page, added the data-scroll-reveal
attribute to the svg and then the image disappeared. 我在页面底部添加了js代码,向svg添加了data-scroll-reveal
属性,然后图像消失了。
Can anyone help? 有人可以帮忙吗?
I use this function for these types of things 我将这种功能用于这类事情
// Returns true when element is mostly visible in the viewport
// -------------------------------
isElementInViewport: function (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}
test with it like this 像这样测试
if(isElementInViewport(yourElm)){
// elm is in viewport
}
and you will want to watch the scroll. 您将要观看滚动。 Let me know if you need to know how to do that. 让我知道您是否需要知道该怎么做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.