jQuery封装animate.css的实例

2019-11-16,,,,

animate.css是一个有趣的,跨浏览器的css3动画库。

一、首先引入animate css文件

<link rel="stylesheet" href="animate.css" rel="external nofollow" >

二、给指定的元素加上指定的动画样式名

<div id="box" class="animated bounce"></div>

这里包括两个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封装animate.css的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持北冥有鱼。

您可能感兴趣的文章:

  • jQuery Animation实现CSS3动画示例介绍
  • jQuery中使用animate自定义动画的方法

《jQuery封装animate.css的实例.doc》

下载本文的Word格式文档,以方便收藏与打印。