JavaScript缓动插件介绍

摘要:
flash中早已经实现了缓动效果,并且一些技术网站上已经提供了js版本的实现。写这个目的是告诉那些没接触过缓动的朋友js也是可以实现缓动效果的,最经典的应用就是在地图上实现轨迹播放时车辆的缓动。//importtheGreenSockclasses//importcom.greensock.*;//importcom.greensock.easing.*;//-------------这些代码你可以从官方下载处获得//tweentheMovieClipnamed"mc"toanalphaof0.5overthecourseof3secondsTweenLite.to;//scalemyButtonto150%usingtheElastic.easeOuteasefor2secondsTweenLite.to;//tweenmc3inFROM100pixelsabovewhereveritisnow,andanalphaof0.TweenLite.from;//afteradelayof3seconds,tweenmcfor5seconds,slidingitacrossthescreenbychangingits"x"propertyto300,usingtheBack.easeOuteasetomakeitshootpastitandcomeback,andthencalltheonFinishTween()function,passingtwoparameters:5andmcTweenLite.to;functiononFinishTween:void{trace("Thetweenhasfinished!param1="+param1+",andparam2="+param2);}//callmyFunction()after2seconds,passing1parameter:"myParam"TweenLite.delayedCall;//usetheobject-orientedsyntaxtocreateaTweenLiteinstanceandstoreitsowecanreverse,restart,orpauseitlater.varmyTween:TweenLite=newTweenLite;//sometimelater,reversethetween,causingittogobackwardstoitsbeginningfromwhereveritisnow.myTween.reverse();//pausethetweenmyTween.pause();//restartthetweenmyTween.restart();//makethetweenjumptoexactlyits2-secondpointmyTween.currentTime=2;3、说明:、这种缓动效果是基于像素的改变而实现的。改变alpha值,可处理PNG图片不透明。

前言:我们在很多时候都需要实现DOM元素在视图里面缓动,所以我们需求解决办法。flash中早已经实现了缓动效果,并且一些技术网站上已经提供了js版本的实现。写这个目的是告诉那些没接触过缓动的朋友js也是可以实现缓动效果的,最经典的应用就是在地图上实现轨迹播放时车辆的缓动。

1、JavaScript缓动插件:

TweenLite.js,TweenLite.Min.js,TweenLineLite.js,TweenLineMax.js

您可以从这里下载:http://www.greensock.com/get-started-js/

2、TweenLite的使用:

导入TweenLite.js到指定的页面(同样使用于AS脚本的编写)。

//import the GreenSock classes
//importcom.greensock.*;
//importcom.greensock.easing.*;//-------------这些代码你可以从官方下载处获得(此处是AS的代码,js的类似)
//tween the MovieClip named "mc" to an alpha of 0.5 over the course of 3 seconds
TweenLite.to(mc, 3, {alpha:0.5});
//scale myButton to 150% (scaleX/scaleY of 1.5) using the Elastic.easeOut ease for 2 seconds
TweenLite.to(myButton, 2, {scaleX:1.5, scaleY:1.5, ease:Elastic.easeOut});
//tween mc3 in FROM 100 pixels above wherever it is now, and an alpha of 0. (notice the vars object defines the starting values instead of the ending values)
TweenLite.from(mc3, 1, {y:"-100", alpha:0});
//after a delay of 3 seconds, tween mc for 5 seconds, sliding it across the screen by changing its "x" property to 300, using the Back.easeOut ease to make it shoot past it and come back, and then call the onFinishTween() function, passing two parameters: 5 and mc
TweenLite.to(mc, 5, {delay:3, x:300, ease:Back.easeOut, onComplete:onFinishTween, onCompleteParams:[5, mc]});
functiononFinishTween(param1:Number, param2:MovieClip):void{
trace("The tween has finished! param1 = "+ param1 + ", and param2 = "+ param2);
}
//call myFunction() after 2 seconds, passing 1 parameter: "myParam"
TweenLite.delayedCall(2, myFunction, ["myParam"]);
//use the object-oriented syntax to create a TweenLite instance and store it so we can reverse, restart, or pause it later.
varmyTween:TweenLite = newTweenLite(mc2, 3, {y:200, alpha:0.5, onComplete:myFunction});
//some time later (maybe in by a ROLL_OUT event handler for a button), reverse the tween, causing it to go backwards to its beginning from wherever it is now.
myTween.reverse();
//pause the tween
myTween.pause();
//restart the tween
myTween.restart();
//make the tween jump to exactly its 2-second point
myTween.currentTime = 2;
3、说明:
(1)、这种缓动效果是基于像素的改变而实现的。
(2)、Alpha通道是一个8位的灰度通道,该通道用256级灰度来记录图像中的透明度信息,定义透明、不透明和半透明区域,其中黑表示全透明,白表示不透明,灰表示半透明。改变alpha值,可处理PNG图片不透明。简单而言,阿尔法通道(Alpha Channel)是指一张图片的透明和半透明度。
(3)、对于其他插件,找到下载地址就可以看到相关的介绍和例子了,这里不再赘述。

免责声明:文章转载自《JavaScript缓动插件介绍》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇universal link使用【转】TCP/UDP简易通信框架源码,支持轻松管理多个TCP服务端(客户端)、UDP客户端下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

HP服务器设置iLO

HP Server Setting iLO Step 1.开机后出现界面-按F11进入BootMenu;2.选择GenericUSBBoot并输入;3.选择SystemConfiguration(系统配置)并按Enter键;4.选择iLO4ConfigurationUtility进入;5.选择NetworkOptions Enter将DHCPEnable设置...

Linux snmp导入MIB库

Linux中使用的net-snmp带有一些标准MIB,但世界上有无数种支持snmp的设备,每个制造商都有自己的定义。这些定义不能包含在net-snmp附带的MIB中。因此,如果要正确轮询此类设备,必须加载制造商自己的MIB文件。...

thinkphp3.2配置redis缓存和文件缓存

如果您将一些常用但不易更改的数据存储在缓存中,而不是每次检查数据库,则可以大大减轻数据库的压力。最近,由于项目的需要,您尝试了Redis,但后来使用tp3.2文件缓存直接进入主题:在config中添加以下代码。php:“DATA_CACHE_PREFIX”=˃“tp”,//缓存前缀“DATA_CCACHE_TYPE”=˃“Redis”,//高速缓存类型“Re...

【使用 DOM】为DOM元素设置样式

DOCTYPE html˃设置DOM元素的样式p{border:中双绿色;背景颜色:浅灰色;}#block1{color:白色;}table{border:thinsolided;border collapse:collapse;margin:5px;float:left;}td{padding:2px;}#block2{color:yellow;font-...

GIS中的数据库.gdb与.mdb的区别

Gdb是文件地理数据库,mdb是个人地理数据库,两者都是数据库文件类型。个人地理数据库是基于access数据库的个人数据库格式mdb,可存储不超过2G的文件,仅适用于Windows系统;文件数据库是保存在文件系统文件夹中的各种类型的GIS数据集的集合。请参阅文章“GIS中database.gdb和.mdb之间的区别是什么?”,m892832piczpec5。...

C# winform开发嵌套Chrome内核浏览器(WebKit.net)开发(一)

//Www.cnblogs.com/Maxq/p/6566558.htmlWebKit.net是WebKit的一个net包。使用它,。net程序可以非常方便地集成和使用webkit作为加载网页的容器。EventArgse){WebKit.WebKitBrowser=newWebKitBrowser();this.Controls.Add(浏览器);...