动画库 Tweenmax 使用示例1 - 执行动画
来源:互联网 发布:长沙知豆电动车租赁 编辑:程序博客网 时间:2024/05/16 16:24
TweenMax 建立在TweenLite 核心类以及它的大哥TweenFilterLite 基础之上,它为Tween 家族增加了新的受欢迎的功能(尽管只是锦上添花),从而使家族更加的壮大,比如贝赛尔缓动、暂停/继续能力,简便的连续缓、16进制颜色缓动、以及更多的内容。
直接开始!!!
得到动画的实例 new
TweenMax提供了TimelineMax()方法用来得到实例
TweenMax依赖jQuery
<script src="js/jquery-1.11.1.min.js"></script><script src="js/uncompressed/TweenMax.js"></script><script> $(function () { var t = new TimelineMax(); });</script>
添加动画 to()
to()方法参数说明
1. 元素选择器或对象2. 持续时间3. 对象4. 【可选】动画延迟发生时间可写数字,"-=0.5","+=0.5"
页面中插入一个div
<style> #div1 { width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 0; }</style><body> <div id="div1"></div></body>
执行单条动画
<script> t.to("#div1", 1, { left: 300 });</script>
执行组合动画
<script> t.to("#div1", 1, { left: 300, width: 300 });</script>
执行队列动画,列表中的动画会依次执行
<script> t.to("#div1", 1, { left: 300 }); t.to("#div1", 1, { width: 300 }); t.to("#div1", 1, { height: 300 }); t.to("#div1", 1, { top: 300 }); t.to("#div1", 1, { rotationZ: 180 }); t.to("#div1", 1, { opacity: 0 });</script>
通过这样的动画队列,代码比以前利用回调函数来写要清晰很多
添加第四个参数 设置动画的延迟时间
<script> //动画延迟一秒执行 t.to("#div1", 1, { left: 300, width: 300 }, 1); //第二条动画没有延迟时间,所以等第一条动画执行完成后立刻执行第二条动画 t.to("#div1", 1, { width: 300 });</script>
<script> //动画延迟一秒执行 t.to("#div1", 1, { left: 300, width: 300 }, 1); //第二条动画也是延迟一秒执行,会和第一条动画同时延迟一毛执行 t.to("#div1", 1, { width: 300 }, 1);</script>
延迟执行第二条动画
<script> //动画延迟一秒执行 t.to("#div1", 1, { left: 300, width: 300 }, 1); //实现第一条动画完成后,延迟一秒,执行第二条动画 t.to("#div1", 1, { width: 300 }, 3);</script>
延迟执行第二条动画(便捷写法)
<script> //动画延迟一秒执行 t.to("#div1", 1, { left: 300, width: 300 }, 1); t.to("#div1", 1, { width: 300 }, "+=1");</script>
让第二条动画指令立刻执行
<script> //动画延迟一秒执行 t.to("#div1", 1, { left: 300, width: 300 }, 1); //第四个参数设0后,动画会立刻执行 t.to("#div1", 1, { width: 300 }, 0);</script>
动画的停止与播放
通过play()方法与stop()方法来控制
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style> #div1 { width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 50px; } </style> <script src="js/jquery-1.11.1.min.js"></script> <script src="js/uncompressed/TweenMax.js"></script> <script> $(function () { //得到对象 var t = new TimelineMax(); //队列动画 t.to("#div1", 1, { left: 300, width: 300 }); t.to("#div1", 1, { width: 300 }); t.to("#div1", 1, { height: 300 }); t.to("#div1", 1, { top: 300 }); t.to("#div1", 1, { rotationZ: 180 }); t.to("#div1", 1, { opacity: 0 }); //先把动画停止 t.stop(); //播放动画按钮 $("#play").click(function () { t.play(); }); //停止动画按钮 $("#stop").click(function () { t.stop(); }); }); </script></head><body> <input type="button" id="play" value="播放" /> <input type="button" id="stop" value="停止" /> <div id="div1"></div></body></html>
反向执行动画
通过reverse()方法让动画反向执行
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style> #div1 { width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 50px; } </style> <script src="js/jquery-1.11.1.min.js"></script> <script src="js/uncompressed/TweenMax.js"></script> <script> $(function () { //得到对象 var t = new TimelineMax(); //队列动画 t.to("#div1", 1, { left: 300, width: 300 }); t.to("#div1", 1, { width: 300 }); t.to("#div1", 1, { height: 300 }); t.to("#div1", 1, { top: 300 }); t.to("#div1", 1, { rotationZ: 180 }); t.to("#div1", 1, { opacity: 0 }); //反向播放按钮 $("#reverse").click(function () { t.reverse(); }); }); </script></head><body> <input type="button" id="reverse" value="反向播放" /> <div id="div1"></div></body></html>
1 0
- 动画库 Tweenmax 使用示例1 - 执行动画
- 动画库 Tweenmax 使用示例2 - 事件和状态
- TweenMax动画库学习-陈亚博客
- tweenMAX 快速开发tween动画
- Tweenmax.js 绳索动画效果
- GreenSock动画平台学习笔记(二)TweenMax
- GreenSock动画平台学习笔记(二)TweenMax
- 转-Lottie开源动画库介绍与使用示例
- 转-Lottie开源动画库介绍与使用示例
- Lottie开源动画库介绍与使用示例
- 动画的执行--ios动画
- 使用plist创建精灵并执行动画
- 使用plist创建精灵并执行动画
- 使用plist创建精灵并执行动画
- 使用AnimatorSet控制动画执行顺序
- android使用属性动画执行抖动效果
- Lottie动画库使用方法详解 教程 示例
- Android --- Frame动画示例
- oracl 11 无法将空表导出,
- iostat命令——用于输出CPU和磁盘I/O相关的统计信息
- android 处理程序全局异常和错误,UncaughtExceptionHandler
- Install Cassandra on windows
- mongo分组聚合(sum)在java中的用户:Aggregation agg = newAggregation();
- 动画库 Tweenmax 使用示例1 - 执行动画
- 读书笔记2---JavaScript number(数字)类型数据
- 关于Android的Dialog
- android二维码扫描、读取、识别、生成、带logo
- 数据结构实验-用C++实现带头结点的循环链表
- php设定错误和异常处理可使用的函数
- hdu1732 Push Box ---- BFS
- 设计模式汇总:结构型模型(下)
- ios8和之前系统[UIScreen mainScreen].bounds的不一样