最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - css3 animation using html5 data attribute - Stack Overflow

programmeradmin1浏览0评论

I am trying to use one of the css animation framework called Animate.css in a way that I can effectively manage multiple animations.

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

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

So when document is loaded the div should start executing fadeInUp animation from the css framework referenced.

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.

I must have got something wrong, it doesn't do anything.

Here is my JS Fiddle

I am trying to use one of the css animation framework called Animate.css in a way that I can effectively manage multiple animations.

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

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

So when document is loaded the div should start executing fadeInUp animation from the css framework referenced.

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.

I must have got something wrong, it doesn't do anything.

Here is my JS Fiddle

Share Improve this question edited Nov 20, 2013 at 8:32 Seong Lee asked Nov 20, 2013 at 8:27 Seong LeeSeong Lee 10.6k25 gold badges73 silver badges108 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4
$(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/9aE2N/5/

If you do not want to use jQuery you can add the classes (animated fadeInUp):

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

评论列表(0)

  1. 暂无评论