dojo 九 effects dojo/_base/fx 和 dojo/fx
官方教程:Dojo Effects
这里讲学习一下dojo如何实现淡入、淡出、滑动等效果。
实现这些特殊的效果有两个包 dojo/_base/fx 和
dojo/fx。
dojo/_base/fx 中提供了一些基础的animation方法,如: animateProperty,
anim, fadeIn, and fadeOut.
dojo/fx
中提供了一些高级的animation方法,如:chain, combine,
wipeIn, wipeOut and
slideTo。
淡入淡出require(["dojo/_base/fx",
"dojo/on", "dojo/dom",
"dojo/domReady!"],
function(fx, on, dom) {
        var fadeOutButton =
dom.byId("fadeOutButton"),//淡出按钮            fadeInButton =
dom.byId("fadeInButton"),//淡入按钮            fadeTarget =
dom.byId("fadeTarget");//目标节点        on(fadeOutButton,
"click",
function(evt){            fx.fadeOut({ node: fadeTarget
}).play();//淡出        });        on(fadeInButton,
"click",
function(evt){            fx.fadeIn({ node: fadeTarget
}).play();//淡入        });    });在所有的方法中包含后面介绍的,都只有一个对象参数,这个对象中可包含多个属性,必不可少的一个属性就是node,为要实现效果的节点对象或id字符串。
在fadeOut/fadeIn方法中还有一个属性duration,持续的时间,默认为350ms。这些animation方法将返回一animation对象,该对象包含一些方法:play,
pause, stop, status, and
gotoPercent,用来执行,暂停,停止,查看状态及执行到某种程度。
擦除require(["dojo/fx",
"dojo/on", "dojo/dom",
"dojo/domReady!"],
function(fx, on, dom) {
        var wipeOutButton =
dom.byId("wipeOutButton"),            wipeInButton =
dom.byId("wipeInButton"),            wipeTarget =
dom.byId("wipeTarget");        on(wipeOutButton,
"click",
function(evt){            fx.wipeOut({ node: wipeTarget
}).play();        });        on(wipeInButton,
"click",
function(evt){            fx.wipeIn({ node: wipeTarget
}).play();        });    });
同淡入淡出一样
滑动
require(["dojo/fx",
"dojo/on", "dojo/dom",
"dojo/domReady!"],
function(fx, on, dom) {
        var slideAwayButton =
dom.byId("slideAwayButton"),            slideBackButton =
dom.byId("slideBackButton"),            slideTarget =
dom.byId("slideTarget");        on(slideAwayButton,
"click",
function(evt){            fx.slideTo({ node: slideTarget, left:
"200", top: "200"}).play();        });        on(slideBackButton,
"click",
function(evt){            fx.slideTo({ node: slideTarget, left:
"0", top: "100"}).play();        });    });
在slideTo方法的参数中,除了节点对象属性外,还有left和top两个属性,用来设置滑动到目的位置的坐标。
事件
require(["dojo/fx",
"dojo/on", "dojo/dom-style",
"dojo/dom",
"dojo/domReady!"],
function(fx, on, style, dom) {
                 var slideAwayButton =
dom.byId("slideAwayButton"),            slideBackButton =
dom.byId("slideBackButton"),            slideTarget =
dom.byId("slideTarget");                         on(slideAwayButton,
"click",
function(evt){                // Note that we're specifying the
beforeBegin as a property of the animation                // rather than using connect. This
ensures that our beforeBegin handler                // executes before any
others.                var anim =
fx.slideTo({                    node: slideTarget,                    left:
"200",                    top:
"200",                    beforeBegin:
function(){                                                 console.warn("slide
target is: ", slideTarget);                                                 style.set(slideTarget,
{                            left:
"0px",                            top:
"100px"                        });                    }                });                // We could have also specified onEnd
above alongside beforeBegin,                // but it's just as easy to connect like
so                on(anim,
"End", function(){                    style.set(slideTarget,
{                        backgroundColor:
"blue"                    });                },
true);                // Don't forget to actually start the
animation!                anim.play();            });            on(slideBackButton,
"click",
function(evt){                var anim =
fx.slideTo({                    node: slideTarget,                    left:
"0",                    top:
"100",                    beforeBegin:
function(){                                                 style.set(slideTarget,
{                            left:
"200px",                            top:
"200px"                        });                    }                });                on(anim,
"End",
function(){                    style.set(slideTarget,
{                        backgroundColor:
"red"                    });                },
true);                anim.play();            });    });在实现动态效果的过程中会产生两个事件,一个是beforeBegin,在执行之前调用;一个是onEnd,在执行完后调用。
在上面的例子中可以看到,beforeBegin是作为参数对象中的一个方法来定义的;onEnd是作为animation对象的一个事件在on中定义的。
连锁反应require(["dojo/_base/fx",
"dojo/fx", "dojo/on",
"dojo/dom",
"dojo/domReady!"],
function(baseFx, fx, on, dom) {
                 var slideAwayButton =
dom.byId("slideAwayButton"),            slideBackButton =
dom.byId("slideBackButton"),            slideTarget =
dom.byId("slideTarget");                     // Set up a couple of click handlers to run our
chained animations        on(slideAwayButton,
"click",
function(evt){            fx.chain([                baseFx.fadeIn({ node: slideTarget
}),                fx.slideTo({ node: slideTarget, left:
"200", top: "200"}),                baseFx.fadeOut({ node: slideTarget
})            ]).play();        });        on(slideBackButton,
"click",
function(evt){            fx.chain([                baseFx.fadeIn({ node: slideTarget
}),                fx.slideTo({ node: slideTarget, left:
"0", top: "100"}),                baseFx.fadeOut({ node: slideTarget
})            ]).play();        });             });
chain用来将多个animation动作连接起来按顺序执行,它的参数即是由不同animation方法返回的animation对象组成的数组,执行的顺序就是数组的先后顺序。
联合
require(["dojo/_base/fx",
"dojo/fx", "dojo/on",
"dojo/dom",
"dojo/domReady!"],
function(baseFx, fx, on, dom) {
                 var slideAwayButton =
dom.byId("slideAwayButton"),            slideBackButton =
dom.byId("slideBackButton"),            slideTarget =
dom.byId("slideTarget");        // Set up a couple of click handlers to run our
combined animations        on(slideAwayButton,
"click",
function(evt){            fx.combine([                baseFx.fadeIn({ node: slideTarget
}),                fx.slideTo({ node: slideTarget, left:
"200", top: "200"})            ]).play();        });        on(slideBackButton,
"click",
function(evt){            fx.combine([                fx.slideTo({ node: slideTarget, left:
"0", top: "100"}),                baseFx.fadeOut({ node: slideTarget
})            ]).play();        });             });
combine方法是将多个animation动作联合起来同时执行实现一个完成的动态效果。其参数也是由不同animation方法返回的animation对象组成的数组。dojo 九 effects dojo/_base/fx 和 dojo/fx的更多相关文章
- 实践torch.fx第二篇-fx量化实操
		好久不见各位,哈哈,又鸽了好久. 本文紧接上一篇<实践torch.fx第一篇--基于Pytorch的模型优化量化神器>继续说,主要讲如何利用FX进行模型量化. 为什么这篇文章拖了这么久,有 ... 
- dojo对数组的处理函数,dojo.forEach、dojo.every、 dojo.some、 dojo.map等
		转自:http://jiataodong.blog.163.com/blog/static/3490549220111024111943439/ 数组处理是 Ajax 应用开发中的常见操作.Dojo ... 
- 为什么使用dojo?dojo与jquery有什么不同?dojo适合什么开发场景?
		首先介绍一下dojo的特性: 1.Dojo是一个符合AMD规范的企业级框架(dojo是一个重量级框架) 2.Dojo全面支持异步加载JS机制(即:支持通过require异步加载JS模块,通过defin ... 
- C#读写三菱Fx PLC 使用Fx 串口协议 读写Fx3U设备
		本文将使用一个Github开源的组件库技术来读写三菱 FX PLC,使用的是基于串口的实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 github地 ... 
- Dojo特效(翻译)
		http://dojotoolkit.org/documentation/tutorials/1.10/effects/index.html In this tutorial, we will exp ... 
- dojo框架笔记
		一.模块定义 1.定义只含值对,没有任何依赖的模块(moudle1.js) define({ color: "black", size: "unisize" } ... 
- Dojo动画原理解析
		dojo中动画部分分为两部分:dojo/_base/fx, dojo/fx.dojo/_base/fx部分是dojo动画的基石,里面有两个底层API:animateProperty.anim和两个常用 ... 
- Hello Dojo!(翻译)
		http://dojotoolkit.org/documentation/tutorials/1.10/hello_dojo/index.html 欢迎学习DOJO!在本教程中,你将学些到如何加载DO ... 
- Dojo API中文 Dojo内容模块概览,初学者
		官网:http://dojotoolkit.org/reference-guide/1.10/dojo/index.html#dojo-dojo的翻译 dojo 内容: dojo dojo/dojo ... 
随机推荐
- Jenkins-测试自动化(实例1-RF)
			1. Jenkins新建任务列表:RF测试 2. 对任务进行配置: 源码管理:None 构建:Execute Windows batch command (下图中的脚本是robotframework ... 
- Net数值计算MathNet.Numerics类库
			一.Net自带的数值计算:System.Numerics 1.大整数BitInteger 方法:除数和余数.最大公约数 2.复数Complex 属性:实部.虚部.量值.相位 方法:共轭.倒数 二.Ma ... 
- Windows+Apache+MySQL+PHP(WAMP)环境搭建
			运行操作系统:Windows Server 2008 R2 Apache版本:Apache 2.2 MySQL版本:MySQL 5.5 PHP版本:PHP 5.6.14(当前最新版) 更新日期:201 ... 
- phonegap/cordova常用命令
			创建项目 cordova create foldername com.wps.test projectName cd foldername 基本设备信息 设备 API: cordova plugin ... 
- Kali-linux安装之后的简单设置
			1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb http:/ ... 
- asp.net中实现群发邮件功能
			前段时间在帮老师开发的网站中需要用到一个群发邮件的功能,而自己之前学习cms系统的时候用的we7的群发邮件功能也有一些问题,于是乎便自己去网上查了一下资料,自己总结了一下,并且封装成了一个类,亲测有用 ... 
- AssetBundle依赖关系
			原地址:http://www.cnblogs.com/realtimepixels/p/3652086.html Unity AssetBundle Dependencies In the last ... 
- Java 中最常见的 5 个错误
			在编程时,开发者经常会遭遇各式各样莫名错误.近日,Sushil Das 在 Geek On Java上列举了 Java 开发中常见的 5 个错误,与君共「免」. 原文链接:Top 5 Common M ... 
- netaddr 0.7.12
			Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses https://pypi.python.org/pyp ... 
- Android 检查设备是否存在 导航栏 NavigationBar
			尊重原创.尊重作者,转载请标明出处: http://blog.csdn.net/lnb333666/article/details/41821149 目前也没有可靠的方法来检查设备上是否有导航栏.可以 ... 
