animate.css是一个有趣的,跨浏览器的css3动画库。
一、首先引入animate css文件
<link rel="stylesheet" href="animate.css" rel="external nofollow" >
二、给指定的元素加上指定的动画样式名
<p id="box" class="animated bounce"></p>
这里包括两个class名,第一个是基本的,必须添加的样式名,任何想实现的元素都得添加这个。第二个是指定的动画样式名。
三、如果说想给某个元素动态添加动画样式,可以通过jquery来实现
给动画对象添加类,然后监听动画结束事件,一旦监听到动画结束,立即移除前面添加的类。
官方给出了jquery的封装:
//扩展$对象,添加方法animatecss $.fn.extend({ animatecss: function (animationname) { var animationend = 'webkitanimationend mozanimationend msanimationend oanimationend animationend'; $(this).addclass('animated ' + animationname).one(animationend, function() { $(this).removeclass('animated ' + animationname); }); } }); //调用示例: $('#box').animatecss('bounce');
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery的表单验证提交
jquery的复选框选择并且获取值
jquery ajax异步跨域怎么实现
以上就是如何用jquery封装animate.css代码的详细内容。
