javascript原生移动云编程6 - 如何做动画效果
来源:互联网 发布:阿里云对象存储价格 编辑:程序博客网 时间:2024/05/21 09:34
用javascript在码实云平台上,可以在云里编写原生的移动应用。移动应用的交互界面,添加动画效果,如果恰到好处,能够极大地提升用户体验。可以说,添加动画,是让用户尖叫的一个必要的元素。下面实例中,做了三个会动的按钮。
Class.create(Mash5.Widget, {initialize : function (config, params) {var container = Ti.UI.createView({width : Ti.UI.FILL,height : Ti.UI.FILL,backgroundColor : '#ddd'});this.setContentView(container);var button1 = Ti.UI.createView({ bottom: dipToPx(-100), width: '160dip', height: '40dip', backgroundColor : '#0d4', borderRadius: dipToPx(20),});container.add(button1);button1.add(Ti.UI.createLabel({text: '我会动',color: '#fff',font: {fontSize : '20dip'},}));var button2 = Ti.UI.createView({ top: '100dip', width: '160dip', height: '40dip', backgroundColor : '#d80', borderRadius: dipToPx(20),});container.add(button2);button2.add(Ti.UI.createLabel({text: '我更会动',color: '#fff',font: {fontSize: '20dip'},}));var button3 = Ti.UI.createView({ width: '160dip', height: '40dip', backgroundColor : '#80d', borderRadius: dipToPx(20),});container.add(button3);button3.add(Ti.UI.createLabel({text: '我会动3次',color: '#fff',font: {fontSize : '20dip'},})); // 添加动画效果var a1 = Titanium.UI.createAnimation();a1.duration = 500;a1.bottom = dipToPx(100);button1.animate(a1); var matrix = Ti.UI.create2DMatrix(); button2.transform = matrix.translate(0, dipToPx(-300)).rotate(150); button2.opacity = 0.3;var a2 = Titanium.UI.createAnimation();a2.duration = 1500;a2.delay = 500;a2.transform = matrix;a2.opacity = 1;button2.animate(a2); var m3 = Ti.UI.create2DMatrix(); button3.transform = m3.translate(dipToPx(-200), dipToPx(-500)).rotate(150).scale(5, 5); button3.opacity = 0;var a3 = Titanium.UI.createAnimation();a3.duration = 2000;a3.delay = 2000;a3.autoreverse = true;a3.repeat = 3;a3.transform = m3;a3.opacity = 1;button3.animate(a3);}})
这个实例给大家示意动画的编程方法。第一个按钮button1的动画最简单,是个针对bottom垂直平移的效果。事先用Titanium.UI.createAnimation准备好动画变量。这个变量设定好动画最终的结果数值,动画结束时会到达a1.bottom = dipToPx(100)。第二个按钮的动画效果丰富些,用了二维变换的矩阵Ti.UI.create2DMatrix。有了这个矩阵,可以方便地设定平移、旋转、缩放。通过button2.transform = matrix.translate(0, dipToPx(-300)).rotate(150),我们先把按钮2垂直向上移动300,然后转150度,动画从这个位置开始,恢复到按钮2的原始位置结束。第三个按钮的动画则综合了平移、旋转、放大三种变换,动画里用了回播和重复。
0 0
- javascript原生移动云编程6 - 如何做动画效果
- javascript原生移动云编程4 - 如何做图文并茂的博客页面UI
- javascript原生移动云编程5 - 如何做互动按钮和页面跳转
- javascript原生移动云编程7 - 如何调用云数据服务显示实时天气
- javascript原生移动云编程9 - 如何使用云数据库读取和保存数据
- javascript原生移动云编程8 - 如何插入任意web页面
- javascript原生移动云编程10 - 如何调用相机并上传下载图片视频
- javascript原生移动云编程11 - 如何调用手机图库中图片
- javascript原生移动云编程14 - 如何隐藏和定制屏幕上部的导航条
- javascript原生移动云编程(编外) - javascript速成答疑
- Javascript原生动画效果的实现
- javascript原生移动云编程2 - 原生移动UI的起点
- javascript原生移动云编程1 - 十分钟做出跨平台原生App
- HTML5+原生javascript移动端滑动banner效果demo
- js原生动画效果
- javascript dom 编程艺术 动画效果
- javascript原生移动云编程3 - 比web还简单的页面UI布局
- javascript原生移动云编程12 - 如何用手机录音和播放
- 关于编译器4字节对齐方式比较
- spring使用注解进行DI(依赖)注入
- 安卓中自定义按钮风格文本教程
- linux通过ulimit调整open files数值
- 输入板火爆App Store 搜狗无线战略渐清晰
- javascript原生移动云编程6 - 如何做动画效果
- Xcode调试时无法看到变量值
- 断言(ASSERT)的用法
- objective c - 单例模式(多线程)
- nginx tomcat 集群
- Activity intent经常使用的 FLAG 集合
- Letter Combinations of a Phone Number
- hdu 1108最小公倍数
- 安卓TCP通信程序客户端设计