简体   繁体   English

使用html5数据属性的css3动画

[英]css3 animation using html5 data attribute

I am trying to use one of the css animation framework called Animate.css in a way that I can effectively manage multiple animations. 我试图使用一个名为Animate.css的css动画框架,我可以有效地管理多个动画。

I have a markup like the following for example. 我有一个像下面这样的标记。

<div data-animation="fadeInUp" style="width:100px; height:100px; background-color:#ddd"></div>

And jquery as follows 和jquery如下

$(function () {
    $('div').addClass('animated ' + data('animation'));
});

So when document is loaded the div should start executing fadeInUp animation from the css framework referenced. 因此,当加载文档时,div应该从引用的css框架开始执行fadeInUp动画。

In a real context, I would be using jquery scroll plugin to detect the x, y position to find when to fire animation but this is to just get started. 在真实的上下文中,我将使用jquery滚动插件来检测x,y位置以找到何时触发动画,但这只是开始。

I must have got something wrong, it doesn't do anything. 我一定有错,它什么也没做。

Here is my JS Fiddle 这是我的JS小提琴

$(function () {
    var $divToAnimate = $("div"); // This will animate all the div elements in doc
    $divToAnimate.addClass('animated ' + $divToAnimate.data('animation'));
});

See for instance your Fiddle updated: http://jsfiddle.net/9aE2N/5/ 比如看你的小提琴更新: http//jsfiddle.net/9aE2N/5/

If you do not want to use jQuery you can add the classes (animated fadeInUp): 如果您不想使用jQuery,可以添加类(动画fadeInUp):

<div id="foo" class="animated fadeInUp" data-animation="zoomInDown" style="width:100px; height:100px; background-color:#ddd">
</div>

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

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