简体   繁体   English

没有jQuery的Animate.css?

[英]Animate.css without jQuery?

I am trying to make animation on page scrolling. 我正在尝试在页面滚动时制作动画。

I use the Animate.css library. 我使用Animate.css库。

The documentation only shows how to use it with jQuery, but I'm currently learning how to use Vanilla Javascript. 该文档仅显示了如何在jQuery中使用它,但是我目前正在学习如何使用Vanilla Javascript。 I was trying to use window.pageYOffset but that only works when the browser reaches the container and not when it is revealed by the scroll. 我试图使用window.pageYOffset,但这仅在浏览器到达容器时有效,而在滚动显示时不起作用。

Here's an example how you can animate without jQuery. 这是一个示例,您可以在没有jQuery的情况下进行动画处理。 Investigate the MDN doc page window.onscroll for the scroll event. 研究MDN文档页面window.onscroll的滚动事件。

const $item = document.querySelector('.starred-item');
$item && ($item.classList.add('animated', 'bounce'));

Another example of vanilla JS animation without jQuery (or any other libraries). 没有jQuery(或任何其他库)的香草JS动画的另一个示例。

 var v = 0; var delta = 1; function verticalMove() { redBox = document.getElementById('verticalDiv') v += delta; redBox.style.top = v + "px"; if (v <= 0) delta = 1; if (v >= 50) delta = -1; } function startMove(event) { setInterval(verticalMove, 30); event.target.onclick=""; } 
 .verticalDiv { position: absolute; top: 0px; right: 500px; width: 100px; height: 100px; background: red; } 
 <div class="verticalDiv" id="verticalDiv" onclick="startMove(event)"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM