tween: 1000 velocity动画js里面动画的属性

Velocity.js是一款动画切换的jQuery插件,它重新实现了jQuery的$.animate()方法从而加快动画切换的速度。Velocity.js只有7k的大小,它不仅包含了$.animate()的所有功能,并且还包含了颜色切换、转换(transform)、循环、、CSS切换、Scroll功能,它是、&、&在动画方面的最佳组合。Velocity.js支持IE8+、Chrome、Firefox等浏览器,并支持Andriod以及IOS。Velocity.js在内部实现中使用了jQuery的$.queue()方法,因此它比 jQuery的$.animate()、$.fade()、$.delay()方法更加流畅,其性能也高于CSS的animation属性,具体原理读者可以参考。
Velocity.js包含两个输入参数,第一个参数用于规定产生的动画效果,第二个参数为可选参数,用于规定动画的额外选项。具体如下:
$("div").velocity({
property1: value1,
property2: value2
/* Default options */
duration: 400,
easing: "swing",
queue: "",
complete: null,
loop: false,
delay: false,
display: false,
mobileHA: true
Velocity.js同样支持jQuery的参数简写语法:$element.velocity(propertyMap [, duration] [, easing] [, complete]):,比如:
$("div").velocity({ left: 100 }, 1000);
$("div").velocity({ left: 100 }, 1000, "swing");
$("div").velocity({ left: 100 }, "swing");
Velocity.js官方宣传Velocity的目标是成为DOM中动画切换方面的领导者。读者可以从下载最新版本的Velocity.js,由于Velocity.js的方法签名和$.animate()一样,因此只需将方法名从animate改为velocity即可。在其官方网站给出了几个绚丽的,读者可以参考学习
阅读(...) 评论()你的位置: >
> 极棒的jquery动画切换引擎插件Velocity.js
Velocity.js是一款动画引擎插件,它拥有与中的$.animate()相同的API,还打包了颜色,转换,循环,easing效果,类动画、滚动等功能,因此大家可以像使用$.animate()方法一样使用velocity,您可以快速的上手velocity.js。简单点说:Velocity就是实现页面元素中的飞入,飞出,旋转、颜色变换,esaing效果的jquery。
:Velocity动画插件的使用方法
引入核心文件
&script&src=&/js/jquery/1.11.1/jquery.min.js&&&/script&
&script&src=&velocity.min.js&&id=&library&&&/script&
&div&id=&welcome&&
&p&id=&browserWidthNotice&&
嘿嘿,jQ酷整理
没有&WebGL.&没有&Canvas.&仅仅操作了&DOM.
&&&&&span&id=&count&&175个&/span&&圆角带阴影的div
&a&id=&logo&&href=&index.html&&Velocity&span&id=&logoDot&&.&/span&js&/a&
&div&id=&container&&&/div&
写入CSS,此处的CSS可根椐自己的需求定义,还有不了解CSS3的朋友,请先学习下CSS3,在这就不一一的解释了
padding:&0;
margin:&0;
pointer-events:&
background:&#060b14;
overflow:&
font-family:&&Helvetica&Neue&,&&Open&Sans&;
font-weight:&100;
color:&#4bc2f1;
text-decoration:&
text-decoration:&
#container&{
perspective:&50
-webkit-perspective:&50
-moz-perspective:&50
-ms-perspective:&50
transform-origin:&50%&100%;
-webkit-transform-origin:&50%&100%;
-moz-transform-origin:&50%&100%;
-ms-transform-origin:&50%&100%;
opacity:&0.55;
#welcome&{
position:&
left:&50%;
margin-top:&-1
margin-left:&-11
font-weight:&200;
opacity:&0.65;
text-align:&
font-size:&0.775
line-height:&1.05
letter-spacing:&0.135
word-spacing:&-0.075
@media&screen&and&(max-width:&400px)&{
#welcome&{
font-size:&0.45rem&!
#browserWidthNotice&{
font-style:&
position:&
right:&0.75
bottom:&0.65
text-decoration:&
color:&#d6d6d6;
font-size:&2
letter-spacing:&0.025
#logoDot&{
color:&#d74580;
position:&
height:&30
border-radius:&30
background-color:&#4bc2f1;
写入JS,实现效果
/*****************
&&&& &Summary
&&&&*****************/
&&&&/*&Watch&the&codecast&to&learn&how&this&demo&was&made:&/watch?v=MDLiVB6g2NY&hd=1&*/
&&&&/*&This&demo&serves&two&purposes:
&&&& 1)&Act&as&Velocity's&primary&visual&test&(in&addition&to&the&unit&and&load&tests).
2)&Demonstrate&all&of&Velocity's&features.
3)&Demonstrate&the&performance&capabilties&of&the&DOM;&WebGL&and&Canvas&are&not&used&in&this&demo.
/*&Intended&demo&behavior:&
1)&A&message&box&fades&out.
2)&Dots&are&randomly&assigned&coordinates&and&opacities&then&translated&and&increased&in&opacity.&This&animation&is&then&reversed.
3)&Meanwhile,&the&dots'&container&has&its&perspective,&rotateZ,&and&opacity&animated&in&a&loop&with&a&delay.
4)&Once&the&dot&animation&is&complete,&the&message&box&fades&back&in.
/*********************
&&&&&&&设备类型
&&&&*********************/
var&isWebkit&=&/Webkit/i.test(navigator.userAgent),
isChrome&=&/Chrome/i.test(navigator.userAgent),
isMobile&=&!!(&ontouchstart&&in&window),
isAndroid&=&/Android/i.test(navigator.userAgent),
isIE&=&document.documentM
/******************
&&&& 重定向
&&&&******************/
if&(isMobile&&&&isAndroid&&&&!isChrome)&{
alert(&虽然&Velocity.js&可在所有的手机浏览器上使用,&但本3D实例只在IOS和安卓系统上的谷歌浏览器运行,确定后返回jQ酷首页&);
window.location&=&&http://www.jqcool.net&;
/***************
&&&& Helpers
&&&&***************/
/*&取得两个整数间的随机数&*/
function&r&(min,&max)&{
&&&&return&Math.floor(Math.random()&*&(max&-&min&+&1))&+&
/*&重写essing的默认类型.&*/
$.Velocity.defaults.easing&=&&easeInOutsine&;
/*******************
&&&&&&&&创建圆点
&&&&*******************/
&&&&/*&Differentiate&dot&counts&based&on&roughly-guestimated&device&and&browser&capabilities.&
基于设备和浏览器创建不同的圆点
var&dotsCount,
dotsHtml&=&&&,
$count&=&$(&#count&),
if&(window.location.hash)&{
dotsCount&=&window.location.hash.slice(1);
dotsCount&=&isMobile&?&(isAndroid&?&40&:&60)&:&(isChrome&?&175&:&125);
for&(var&i&=&0;&i&&&dotsC&i++)&{
dotsHtml&+=&&&div&class='dot'&&/div&&;
$dots&=&$(dotsHtml);
$count.html(dotsCount);
/*************
&&&&&&&&Setup
&&&&*************/
var&$container&=&$(&#container&),
$browserWidthNotice&=&$(&#browserWidthNotice&),
$welcome&=&$(&#welcome&);
var&screenWidth&=&window.screen.availWidth,
screenHeight&=&window.screen.availHeight,
chromeHeight&=&screenHeight&-&(document.documentElement.clientHeight&||&screenHeight);
var&translateZMin&=&-725,
translateZMax&=&600;
var&containerAnimationMap&=&{
perspective:&[&215,&50&],
opacity:&[&0.90,&0.55&]
/*&IE10+&produce&odd&glitching&issues&when&you&rotateZ&on&a&parent&element&subjected&to&3D&transforms.&
当在一个父级元素使用3D变型旋转Z轴时IE10+会出现莫名的错误
if&(!isIE)&{
containerAnimationMap.rotateZ&=&[&5,&0&];
/*&Ensure&the&user&is&full-&this&demo's&translations&are&relative&to&screen&width,&not&window&width.&
确保用户使用的是全屏;本实例变形相对于整个屏幕,而不是窗口;
if&((document.documentElement.clientWidth&/&screenWidth)&&&0.80)&{
$browserWidthNotice.show();
/*****************
&&&&&&&&Animation
&&&&*****************/
&&&&/*&Fade&out&the&welcome&message.&
淡淡显示欢迎信息
$welcome.velocity({&opacity:&[&0,&0.65&]&},&{&display:&&none&,&delay:&3500,&duration:&1100&});
/*&Animate&the&dots'&container.
动画出现圆点的容器
$container
.css(&perspective-origin&,&screenWidth/2&+&&px&&&+&((screenHeight&*&0.45)&-&chromeHeight)&+&&px&)
.velocity(containerAnimationMap,&{&duration:&800,&loop:&1,&delay:&3250&});
/*&Special&visual&enhancement&for&WebKit&browsers,&which&are&faster&at&box-shadow&manipulation.&
特别改善webkit浏览器的视觉效果,因为阴影得到更快的控制
if&(isWebkit)&{
$dots.css(&boxShadow&,&&0px&0px&4px&0px&#4bc2f1&);
/*&Animate&the&dots.&
.velocity({&
translateX:&[&
function()&{&return&&+=&&+&r(-screenWidth/2.5,&screenWidth/2.5)&},
function()&{&return&r(0,&screenWidth)&}
translateY:&[
function()&{&return&&+=&&+&r(-screenHeight/2.75,&screenHeight/2.75)&},
function()&{&return&r(0,&screenHeight)&}
translateZ:&[
function()&{&return&&+=&&+&r(translateZMin,&translateZMax)&},
function()&{&return&r(translateZMin,&translateZMax)&}
opacity:&[&
function()&{&return&Math.random()&},
function()&{&return&Math.random()&+&0.1&}
},&{&duration:&6000&})
.velocity(&reverse&,&{&easing:&&easeOutQuad&&})
.velocity({&opacity:&0&},&{&duration:&2000,&complete:&function()&{&
.html(&&a&href='http://www.jqcool.net'&返回jQ酷首页.&/a&&)
.velocity({&opacity:&0.75&},&{&duration:&3500,&display:&&block&&})
.find(&*&).add($welcome).css(&pointer-events&,&&auto&);
.appendTo($container);
以上就是一个完整的实例代码了,因为是个相对综合的例子,所有点复杂。下面来看下velocity的选项吧,简单实用点,嘻嘻。
velocity可以传两个参数,第一个可以像css参数一样传输属性和值,而对象的选项则可以通过第二个参数传递,代码如下:
$element.velocity({&
&&&&width:&&500px&,
&&&&property2:&value2
&&&&/*&Velocity's&default&options&*/
&&&&duration:&400,
&&&&easing:&&swing&,
&&&&queue:&&&,
&&&&begin:&undefined,
&&&&progress:&undefined,
&&&&complete:&undefined,
&&&&display:&undefined,
&&&&visibility:&undefined,
&&&&loop:&false,
&&&&delay:&false,
&&&&mobileHA:&true
Velocity支持单一个参数模式
$element.velocity({&
&&&&properties:&{&opacity:&1&},
&&&&options:&{&duration:&500&}
$element.velocity({&
&&&&p:&{&opacity:&1&},
&&&&o:&{&duration:&500&}
代替对象选项的参数输入,还可以使用像jquery中的逗号分隔模式,但仅限于duration,&easing, andcomplete属性;代码如下
$element.velocity({&top:&50&},&1000);
$element.velocity({&top:&50&},&1000,&&swing&);
$element.velocity({&top:&50&},&&swing&);
$element.velocity({&top:&50&},&1000,&function()&{&alert(&Hi&);&});
转载请注明: &
下载地址: |
与本文相关的文章用惯了jquery的同学,相信都很欣赏其动画引擎。确实相对比较完善!如果,如果想像力足够丰富的话,相信可以做出超出想像的效果。当然,跟2d库比起来,还是相差相当一段距离。jquery压根也不是专门为动画而设计的。模拟真实世界方面,还是不足的。但在web世界里还是游刃有余的。动画其实一直是flash的专属领地(web区哉)。只是它常常沦为黑客攻击的漏洞所在,而且要装插件,有时候文件实在太大,而且性耗实在是高啊。html5出现后,其实adobe自己都转移阵地到html5了。当然,我觉得很长一段时间内,flash是不会被放弃的。
长话短说,步入正题。仿照flash的动画原理,自己写了一个非常简单的js动画引擎。
首先,用过flash的同学都知道。flash有个时间线,上面布满了&帧&。其实每个帧都是一个镜头,镜头连贯起来就是一副动画效果。其实,这跟电影的原理也一样的,小时候玩过胶片的都知道,对着光可以看到一副副的镜头。人眼分辨两个画面的连贯是有时间限度的。如果想看不到两个画面变换时的闪烁大概30帧/秒左右,电影是24帧的。所以,如果能保证,动画切换能保证每秒30次,基本上,就做到了动画的流畅效果,但是这取决环境。所以具体情况,具体而定,其实关于这方面的知识我也是一知半解。就这个动画引擎而言,了解这么多也差不多足够了,有兴趣可以查找相关知识!
下面开始说说设计原理。
首先需要一个帧频,也就是多少帧每秒。如果有了总用时,通过开始和结束的状态差,就可以计算出整个动画下来有多少个&画面&(总帧数)。这就需要几个参数了:初始状态\结束状态\总用时\帧频!
总帧数 = 总用时/1000*帧频
每走一帧,都计算出一个画面!
当前画面=初始状态 + (当前帧/总帧数)(结束状态-初始状态)
这就意味着,如果当前帧是最后一帧的话,当前画面===结束状态。整个过程播放完毕。当然,上面这个例子,是以最简单的直线运动来设计的。真正用的时候,可能远比这个复杂的多,但总体的思想都一样的。这种设计,显然有个不足的地方,不能保证时间正好是个整数帧。所以,我做的时候,向上取整,总用时可能稍长。除非1ms一帧。这是一个网友提出来的,我感觉不好就没有采用。所以这个引擎是有时间误差的。有了总帧数,当动画运行到最后一帧的时候,整个动画也就播放完。如果需要重复播放,重新把当前帧归0。这种动画有一个好处,就可以直接运行到指定帧。也就是flash里的gotoAndStop和gotoAndPlay。其实整个动画设计原理都是照着flash实现的。包括一个很重要的方法:enterFrame,每一帧计算画面就是能过它来实现的。还有其它一些方法:stop、play、next......等等因为目前来说,这个引擎是写非常简单和粗糙的,先不说这么详细了。下面先上代码和示例吧!
animate.js 动画核心
var animation = function(obj) {
this.obj =
this.frames = 0;
this.timmer =
this.running = false;
this.ms = [];
animation.prototype = {
init: function(props, duration, tween) {
//console.log('初始化');
this.curframe = 0;
this.initstate = {};
this.props =
this.duration = duration || 1000;
this.tween = tween || function(t, b, c, d) {
return t * c / d +
this.frames = Math.ceil(this.duration * this.fps/1000);
for (var prop in this.props) {
this.initstate[prop] = {
from: parseFloat($util.dom.getStyle(this.obj, prop)),
to: parseFloat(this.props[prop])
start: function() {
if (!this.running && this.hasNext()) {
//console.log('可以执行...');
this.ms.shift().call(this)
return this;
//开始播放
play: function(callback) {
//console.log('开始动画!');
var that = this;
this.running = true;
if (this.timmer) {
this.stop();
this.timmer = setInterval(function() {
if (plete()) {
that.stop();
that.running = false;
if (callback) {
callback.call(that);
that.curframe++;
that.enterFrame.call(that);
1000 / this.fps);
return this;
// 停止动画
stop: function() {
//console.log('结束动画!');
if (this.timmer) {
clearInterval(this.timmer);
// 清除掉timmer id
this.timmer =
go: function(props, duration, tween) {
var that = this;
//console.log(tween)
this.ms.push(function() {
that.init.call(that, props, duration, tween);
that.play.call(that, that.start);
return this;
//向后一帧
next: function() {
this.stop();
this.curframe++;
this.curframe = this.curframe & this.frames ? this.frames: this.
this.enterFrame.call(this);
//向前一帧
prev: function() {
this.stop();
this.curframe--;
this.curframe = this.curframe & 0 ? 0 : this.
this.enterFrame.call(this);
//跳跃到指定帧并播放
gotoAndPlay: function(frame) {
this.stop();
this.curframe =
this.play.call(this);
//跳到指定帧停止播放
gotoAndStop: function(frame) {
this.stop();
this.curframe =
this.enterFrame.call(this);
//进入帧动作
enterFrame: function() {
//console.log('进入帧:' + this.curframe)
for (var prop in this.initstate) {
//console.log('from: ' + this.initstate[prop]['from'])
ds = this.tween(this.curframe, this.initstate[prop]['from'], this.initstate[prop]['to'] - this.initstate[prop]['from'], this.frames).toFixed(2);
//console.log(prop + ':' + ds)
$util.dom.setStyle(this.obj, prop, ds)
//动画结束
complete: function() {
return this.curframe &= this.
hasNext: function() {
return this.ms.length & 0;
下面是一个简单的工具,其中有所用到的缓动公式:
* 类型检测
type : function(obj){
var rep = /\[object\s+(\w+)\]/i;
var str = Object.prototype.toString.call(obj).toLowerCase();
str.match(rep);
return RegExp.$1;
$unlink :function (object){
switch ($type(object)){
case 'object':
unlinked = {};
for (var p in object) {
unlinked[p] = $unlink(object[p]);
case 'array':
unlinked = [];
for (var i = 0, l = object. i & i++) {
unlinked[i] = $unlink(object[i]);
default: return
*Dom 相关操作
$: function(id) {
return document.getElementById(id);
getStyle: function(obj, prop) {
var style = obj.currentStyle || window.getComputedStyle(obj, '');
if (obj.style.filter) {
return obj.style.filter.match(/\d+/g)[0];
return style[prop];
setStyle: function(obj, prop, val) {
switch (prop) {
case 'opacity':
if($util.client.browser.ie){
obj.style.filter = 'alpha(' + prop + '=' + val*100 + ')'
obj.style[prop] =
obj.style[prop] = val + 'px';
setStyles: function(obj, props) {
for (var prop in props) {
switch (prop) {
case 'opacity':
if($util.client.browser.ie){
obj.style.filter = 'alpha(' + prop + '=' + props[prop] + ')'
obj.style[prop] = props[prop];
obj.style[prop] = props[prop] + 'px';
*Event 事件相关
addEvent : function(oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
oTarget["on" + sEventType] = fnH
rmEvent : function removeEventHandler (oTarget, sEventType, fnHandler) {
if (oTarget.removeEventListener) {
oTarget.removeEventListener(sEventType, fnHandler, false);
} else if (oTarget.detachEvent) {
oTarget.detachEvent("on" + sEventType, fnHandler);
oTarget["on" + sEventType] = null;
*Ajax 异步加载
request:function (options) {
var url = options.url,
context = options.context,
success = options.success,
type = options.type,
datatype = options.datatype,
async = options.async,
send = options.send,
headers = options.
xhr = new XMLHttpRequest();
} catch(e) {
xhr = new ActiveXObject('MSXML2.XMLHTTP');
} catch(e) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
res = xhr.responseT
success(res);
xhr.open(type, url, async);
xhr.send(send);
*Array 数组相关
minIndex : function(ary){
return Math.min.apply(null,ary);
maxitem : function(ary){
return Math.max.apply(null,ary);
*Client 客户端检测
client : function(){
// 浏览器渲染引擎 engines
var engine = {
webkit: 0,
//complete version
var browser = {
//browsers
firefox: 0,
safari: 0,
chrome: 0,
//specific version
// 客户端平台platform/device/OS
var system = {
win: false,
mac: false,
x11: false,
//移动设备
iphone: false,
ipod: false,
ipad: false,
ios: false,
android: false,
nokiaN: false,
winMobile: false,
//game systems
wii: false,
// 检测浏览器引擎
var ua = navigator.userA
if (window.opera){
engine.ver = browser.ver = window.opera.version();
engine.opera = browser.opera = parseFloat(engine.ver);
} else if (/AppleWebKit\/(\S+)/.test(ua)){
engine.ver = RegExp["$1"];
engine.webkit = parseFloat(engine.ver);
//figure out if it's Chrome or Safari
if (/Chrome\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.chrome = parseFloat(browser.ver);
} else if (/Version\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.safari = parseFloat(browser.ver);
//approximate version
var safariVersion = 1;
if (engine.webkit & 100){
safariVersion = 1;
} else if (engine.webkit & 312){
safariVersion = 1.2;
} else if (engine.webkit & 412){
safariVersion = 1.3;
safariVersion = 2;
browser.safari = browser.ver = safariV
} else if (/KHTML\/(\S+)/.test(ua) || /Konqueror\/([^;]+)/.test(ua)){
engine.ver = browser.ver = RegExp["$1"];
engine.khtml = browser.konq = parseFloat(engine.ver);
} else if (/rv:([^\)]+)\) Gecko\/\d{8}/.test(ua)){
engine.ver = RegExp["$1"];
engine.gecko = parseFloat(engine.ver);
//determine if it's Firefox
if (/Firefox\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.firefox = parseFloat(browser.ver);
} else if (/MSIE ([^;]+)/.test(ua)){
engine.ver = browser.ver = RegExp["$1"];
engine.ie = browser.ie = parseFloat(engine.ver);
//detect browsers
browser.ie = engine.
browser.opera = engine.
//detect platform
var p = navigator.
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
//detect windows operating systems
if (system.win){
if (/Win(?:dows )?([^do]{2})\s?(\d+\.\d+)?/.test(ua)){
if (RegExp["$1"] == "NT"){
switch(RegExp["$2"]){
case "5.0":
system.win = "2000";
case "5.1":
system.win = "XP";
case "6.0":
system.win = "Vista";
case "6.1":
system.win = "7";
system.win = "NT";
} else if (RegExp["$1"] == "9x"){
system.win = "ME";
system.win = RegExp["$1"];
//mobile devices
system.iphone = ua.indexOf("iPhone") & -1;
system.ipod = ua.indexOf("iPod") & -1;
system.ipad = ua.indexOf("iPad") & -1;
system.nokiaN = ua.indexOf("NokiaN") & -1;
//windows mobile
if (system.win == "CE"){
system.winMobile = system.
} else if (system.win == "Ph"){
if(/Windows Phone OS (\d+.\d+)/.test(ua)){;
system.win = "Phone";
system.winMobile = parseFloat(RegExp["$1"]);
//determine iOS version
if (system.mac && ua.indexOf("Mobile") & -1){
if (/CPU (?:iPhone )?OS (\d+_\d+)/.test(ua)){
system.ios = parseFloat(RegExp.$1.replace("_", "."));
system.ios = 2;
//can't really detect - so guess
//determine Android version
if (/Android (\d+\.\d+)/.test(ua)){
system.android = parseFloat(RegExp.$1);
//gaming systems
system.wii = ua.indexOf("Wii") & -1;
system.ps = /playstation/i.test(ua);
//return it
*Tween 缓动相关
Linear: function(t, b, c, d) {
return c * t / d +
easeIn: function(t, b, c, d) {
return c * (t /= d) * t +
easeOut: function(t, b, c, d) {
return - c * (t /= d) * (t - 2) +
easeInOut: function(t, b, c, d) {
if ((t /= d / 2) & 1) return c / 2 * t * t +
return - c / 2 * ((--t) * (t - 2) - 1) +
easeIn: function(t, b, c, d) {
return c * (t /= d) * t * t +
easeOut: function(t, b, c, d) {
return c * ((t = t / d - 1) * t * t + 1) +
easeInOut: function(t, b, c, d) {
if ((t /= d / 2) & 1) return c / 2 * t * t * t +
return c / 2 * ((t -= 2) * t * t + 2) +
easeIn: function(t, b, c, d) {
return c * (t /= d) * t * t * t +
easeOut: function(t, b, c, d) {
return - c * ((t = t / d - 1) * t * t * t - 1) +
easeInOut: function(t, b, c, d) {
if ((t /= d / 2) & 1) return c / 2 * t * t * t * t +
return - c / 2 * ((t -= 2) * t * t * t - 2) +
easeIn: function(t, b, c, d) {
return c * (t /= d) * t * t * t * t +
easeOut: function(t, b, c, d) {
return c * ((t = t / d - 1) * t * t * t * t + 1) +
easeInOut: function(t, b, c, d) {
if ((t /= d / 2) & 1) return c / 2 * t * t * t * t * t +
return c / 2 * ((t -= 2) * t * t * t * t + 2) +
easeIn: function(t, b, c, d) {
return - c * Math.cos(t / d * (Math.PI / 2)) + c +
easeOut: function(t, b, c, d) {
return c * Math.sin(t / d * (Math.PI / 2)) +
easeInOut: function(t, b, c, d) {
return - c / 2 * (Math.cos(Math.PI * t / d) - 1) +
easeIn: function(t, b, c, d) {
return (t == 0) ? b: c * Math.pow(2, 10 * (t / d - 1)) +
easeOut: function(t, b, c, d) {
return (t == d) ? b + c: c * ( - Math.pow(2, -10 * t / d) + 1) +
easeInOut: function(t, b, c, d) {
if (t == 0) return
if (t == d) return b +
if ((t /= d / 2) & 1) return c / 2 * Math.pow(2, 10 * (t - 1)) +
return c / 2 * ( - Math.pow(2, -10 * --t) + 2) +
easeIn: function(t, b, c, d) {
return - c * (Math.sqrt(1 - (t /= d) * t) - 1) +
easeOut: function(t, b, c, d) {
return c * Math.sqrt(1 - (t = t / d - 1) * t) +
easeInOut: function(t, b, c, d) {
if ((t /= d / 2) & 1) return - c / 2 * (Math.sqrt(1 - t * t) - 1) +
return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) +
Elastic: {
easeIn: function(t, b, c, d, a, p) {
if (t == 0) return
if ((t /= d) == 1) return b +
if (!p) p = d * .3;
if (!a || a & Math.abs(c)) {
var s = p / 4;
} else var s = p / (2 * Math.PI) * Math.asin(c / a);
return - (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) +
easeOut: function(t, b, c, d, a, p) {
if (t == 0) return
if ((t /= d) == 1) return b +
if (!p) p = d * .3;
if (!a || a & Math.abs(c)) {
var s = p / 4;
} else var s = p / (2 * Math.PI) * Math.asin(c / a);
return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b);
easeInOut: function(t, b, c, d, a, p) {
if (t == 0) return
if ((t /= d / 2) == 2) return b +
if (!p) p = d * (.3 * 1.5);
if (!a || a & Math.abs(c)) {
var s = p / 4;
} else var s = p / (2 * Math.PI) * Math.asin(c / a);
if (t & 1) return - .5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) +
return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c +
easeIn: function(t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c * (t /= d) * t * ((s + 1) * t - s) +
easeOut: function(t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) +
easeInOut: function(t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t /= d / 2) & 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) +
return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) +
easeIn: function(t, b, c, d) {
return c - Tween.Bounce.easeOut(d - t, 0, c, d) +
easeOut: function(t, b, c, d) {
if ((t /= d) & (1 / 2.75)) {
return c * (7.5625 * t * t) +
} else if (t & (2 / 2.75)) {
return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) +
} else if (t & (2.5 / 2.75)) {
return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) +
return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) +
easeInOut: function(t, b, c, d) {
if (t & d / 2) return Tween.Bounce.easeIn(t * 2, 0, c, d) * .5 +
else return Tween.Bounce.easeOut(t * 2 - d, 0, c, d) * .5 + c * .5 +
下面是个应用:
&!DOCTYPE HTML&
&meta http-equiv="Content-Type" content="text/ charset=gb2312"&
&title&无标题文档&/title&
&script src="util.js" type="text/javascript"&&/script&
&script src="animate.js" type="text/javascript"&&/script&
&style type="text/css"&
body{behavior:url("csshover.htc")}
*{padding:0;margin:0}
.mianbox{width:<span style="background-color: #f5f5f5; color: #px;margin:50px auto;height:<span style="background-color: #f5f5f5; color: #px;}
.leftbtn{width:20px;background:#eee;border:1px solid #ddd;float:left;margin-right:8px;height:<span style="background-color: #f5f5f5; color: #px;}
.leftbtn:hover{background:#fff}
.rightbtn{width:20px;background:#eee;border:1px solid #ddd;float:right;height:<span style="background-color: #f5f5f5; color: #px;}
.rightbtn:hover{background:#fff}
.con{width:<span style="background-color: #f5f5f5; color: #px;float:left;height:<span style="background-color: #f5f5f5; color: #px;overflow:hidden;position:relative}
.con ul{ white-space:nowrap;font-size:0;position:absolute;left:0;top:0;}
.con li{display:inline; vertical-align:bottom;margin-right:10px}
&div class="mianbox"&
&div class="leftbtn" id="leftbtn"&&/div&
&div class="con"&
&li&&img src="/85000_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/86392_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/79182_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/68121_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/42186_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/85195_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/78182_2.jpg" width="205" height="240" /&&/li&
&li&&img src="/05124_2.jpg" width="205" height="240" /&&/li&
&div class="rightbtn" id="rightbtn"&&/div&
* @para obj
* @para lbtn 左按钮
* @para rbtn 右按钮
每次滚动的宽
* @para duration 每次运行时间
* @para tween 缓动类型
function scOnce(obj, lbtn, rbtn, w, autotime, duration,tween){
var am = new animation(_ul),
ulen = obj.scrollWidth,
dr = 'left',
that = this;
// 最右端?
function isr(){
return parseInt($util.dom.getStyle(obj, 'left')) &=0;
// 最左端?
function isl(){
return ulen - Math.abs(parseInt($util.dom.getStyle(obj, 'left')))-10 &=
if(isr()&&isl())
this.goleft = function (){
step += -1*w;
am.go({left:step+"px"},duration,tween).start();
this.goright = function (){
am.go({left:step+"px"},duration,tween).start();
// 注册左按钮事件
$util.evt.addEvent(lbtn,'click',function(){
isl()? that.goright():that.goleft();
// 注册右按钮事件
$util.evt.addEvent(rbtn,'click',function(){
isr()? that.goleft():that.goright();
$util.evt.addEvent(rbtn,'mouseover',function(){
clearTimeout(timmer);
$util.evt.addEvent(lbtn,'mouseover',function(){
clearTimeout(timmer);
$util.evt.addEvent(rbtn,'mouseout',function(){
timmer = setInterval(auto,autotime);
$util.evt.addEvent(lbtn,'mouseout',function(){
timmer = setInterval(auto,autotime);
function auto(){
if(isl()){
dr = "right";
if(isr()){
dr = "left";
that['go'+dr]();
timmer = setInterval(auto,autotime);
var _ul = document.getElementsByTagName('ul')[0],
lbtn = document.getElementById('leftbtn'),
rbtn = document.getElementById('rightbtn');
var startgo = new scOnce(_ul,lbtn,rbtn,430,3000,500,$util.tween.Quint.easeInOut);
阅读(...) 评论()

我要回帖

更多关于 velocity 属性 的文章

 

随机推荐