commonJS — 通用方法(for COM)
for COM
github: https://github.com/laixiangran/commonJS/blob/master/src/forCOM.js
代码
/**
* Created by laixiangran on 2016/1/25.
* homepage: http://www.cnblogs.com/laixiangran/
* for COM(命名空间)
*/
(function(undefined) {
var com = window.COM = window.COM || {};
/*
* 产生唯一ID
* */
com.buildGuid = function() {
function guid() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
return (guid()+guid()+"-"+guid()+"-"+guid()+"-"+guid()+"-"+guid()+guid()+guid());
};
/*
* 取得数据的类型(一个参数时)或判定数据的类型(两个参数时)
* @param obj 数据
* @param str 用于判断的数据类型
* */
com.getOrIsType = (function() {
var reg = /^(\w)/,
regFn = function($, $1) {
return $1.toUpperCase();
},
to_s = Object.prototype.toString;
return function(obj, str) {
var result = (typeof obj).replace(reg, regFn);
if (result === "Object" || (result === "Function" && obj.exec) ){ // safari chrome中 type /i/ 为function
if (obj === null) {
result = "Null";
}
else if (obj.window == obj) { // 返回Window的构造器名字
result = "Window";
}
else if (obj.callee) { // 类数组的参数组
result = "Arguments";
}
else if (obj.nodeType === 9) {
result = "Document";
}
else if (obj.nodeName) { // 处理元素节点
result = (obj.nodeName + "").replace("#", "");
}
else if (!obj.constructor || !(obj instanceof Object)) {
if("send" in obj && "setRequestHeader" in obj){//处理IE5-8的宿主对象与节点集合
result = "XMLHttpRequest"
}else if("length" in obj && "item" in obj){
result = "namedItem" in obj ? "HTMLCollection" : "NodeList";
}else{
result = "Unknown";
}
}else {
result = to_s.call(obj).slice(8,-1);
}
}
if (result === "Number" && isNaN(obj)) {
result = "NaN";
}
// safari chrome中 对 HTMLCollection与NodeList的to_s都为 "NodeList",此bug暂时无解
if (str) {
return str === result;
}
return result;
};
})();
/**
* Tween介绍:
* Linear:无缓动效果
* Quadratic:二次方的缓动(t^2)
* Cubic:三次方的缓动(t^3)
* Quartic:四次方的缓动(t^4)
* Quintic:五次方的缓动(t^5)
* Sinusoidal:正弦曲线的缓动(sin(t))
* Exponential:指数曲线的缓动(2^t)
* Circular:圆形曲线的缓动(sqrt(1-t^2))
* Elastic:指数衰减的正弦曲线缓动
* Back:超过范围的三次方缓动((s+1)*t^3 – s*t^2)
* Bounce:指数衰减的反弹缓动
* 每个效果都分三个缓动方式,分别是(可采用后面的邪恶记忆法帮助记忆):
* easeIn:从0开始加速的缓动;
* easeOut:减速到0的缓动;
* easeInOut:前半段从0开始加速,后半段减速到0的缓动。
*
* @param currTime: current time(当前时间)
* @param beginVal: beginning value(初始值)
* @param changeVal: change in value(变化量)
* @param duration: duration(持续时间)
*/
com.tween = {
"Linear": function(currTime, beginVal, changeVal, duration) {
return changeVal*currTime/duration + beginVal;
},
"Quad": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return changeVal * (currTime /= duration) * currTime + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return -changeVal *(currTime /= duration)*(currTime-2) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if ((currTime /= duration / 2) < 1) return changeVal / 2 * currTime * currTime + beginVal;
return -changeVal / 2 * ((--currTime) * (currTime-2) - 1) + beginVal;
}
},
"Cubic": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return changeVal * (currTime /= duration) * currTime * currTime + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return changeVal * ((currTime = currTime/duration - 1) * currTime * currTime + 1) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if ((currTime /= duration / 2) < 1) return changeVal / 2 * currTime * currTime*currTime + beginVal;
return changeVal / 2*((currTime -= 2) * currTime * currTime + 2) + beginVal;
}
},
"Quart": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return changeVal * (currTime /= duration) * currTime * currTime*currTime + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return -changeVal * ((currTime = currTime/duration - 1) * currTime * currTime*currTime - 1) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if ((currTime /= duration / 2) < 1) return changeVal / 2 * currTime * currTime * currTime * currTime + beginVal;
return -changeVal / 2 * ((currTime -= 2) * currTime * currTime*currTime - 2) + beginVal;
}
},
"Quint": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return changeVal * (currTime /= duration) * currTime * currTime * currTime * currTime + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return changeVal * ((currTime = currTime/duration - 1) * currTime * currTime * currTime * currTime + 1) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if ((currTime /= duration / 2) < 1) return changeVal / 2 * currTime * currTime * currTime * currTime * currTime + beginVal;
return changeVal / 2*((currTime -= 2) * currTime * currTime * currTime * currTime + 2) + beginVal;
}
},
"Sine": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return -changeVal * Math.cos(currTime/duration * (Math.PI/2)) + changeVal + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return changeVal * Math.sin(currTime/duration * (Math.PI/2)) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
return -changeVal / 2 * (Math.cos(Math.PI * currTime/duration) - 1) + beginVal;
}
},
"Expo": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return (currTime==0) ? beginVal : changeVal * Math.pow(2, 10 * (currTime/duration - 1)) + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return (currTime==duration) ? beginVal + changeVal : changeVal * (-Math.pow(2, -10 * currTime/duration) + 1) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if (currTime==0) return beginVal;
if (currTime==duration) return beginVal+changeVal;
if ((currTime /= duration / 2) < 1) return changeVal / 2 * Math.pow(2, 10 * (currTime - 1)) + beginVal;
return changeVal / 2 * (-Math.pow(2, -10 * --currTime) + 2) + beginVal;
}
},
"Circ": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return -changeVal * (Math.sqrt(1 - (currTime /= duration) * currTime) - 1) + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
return changeVal * Math.sqrt(1 - (currTime = currTime/duration - 1) * currTime) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if ((currTime /= duration / 2) < 1) return -changeVal / 2 * (Math.sqrt(1 - currTime * currTime) - 1) + beginVal;
return changeVal / 2 * (Math.sqrt(1 - (currTime -= 2) * currTime) + 1) + beginVal;
}
},
"Elastic": {
easeIn: function(currTime, beginVal, changeVal, duration, a, p) {
var s;
if (currTime==0) return beginVal;
if ((currTime /= duration) == 1) return beginVal + changeVal;
if (typeof p == "undefined") p = duration * .3;
if (!a || a < Math.abs(changeVal)) {
s = p / 4;
a = changeVal;
} else {
s = p / (2 * Math.PI) * Math.asin(changeVal / a);
}
return -(a * Math.pow(2, 10 * (currTime -= 1)) * Math.sin((currTime * duration - s) * (2 * Math.PI) / p)) + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration, a, p) {
var s;
if (currTime==0) return beginVal;
if ((currTime /= duration) == 1) return beginVal + changeVal;
if (typeof p == "undefined") p = duration * .3;
if (!a || a < Math.abs(changeVal)) {
a = changeVal;
s = p / 4;
} else {
s = p/(2*Math.PI) * Math.asin(changeVal/a);
}
return (a * Math.pow(2, -10 * currTime) * Math.sin((currTime * duration - s) * (2 * Math.PI) / p) + changeVal + beginVal);
},
easeInOut: function(currTime, beginVal, changeVal, duration, a, p) {
var s;
if (currTime==0) return beginVal;
if ((currTime /= duration / 2) == 2) return beginVal+changeVal;
if (typeof p == "undefined") p = duration * (.3 * 1.5);
if (!a || a < Math.abs(changeVal)) {
a = changeVal;
s = p / 4;
} else {
s = p / (2 *Math.PI) * Math.asin(changeVal / a);
}
if (currTime < 1) return -.5 * (a * Math.pow(2, 10* (currTime -=1 )) * Math.sin((currTime * duration - s) * (2 * Math.PI) / p)) + beginVal;
return a * Math.pow(2, -10 * (currTime -= 1)) * Math.sin((currTime * duration - s) * (2 * Math.PI) / p ) * .5 + changeVal + beginVal;
}
},
"Back": {
easeIn: function(currTime, beginVal, changeVal, duration, s) {
if (typeof s == "undefined") s = 1.70158;
return changeVal * (currTime /= duration) * currTime * ((s + 1) * currTime - s) + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration, s) {
if (typeof s == "undefined") s = 1.70158;
return changeVal * ((currTime = currTime/duration - 1) * currTime * ((s + 1) * currTime + s) + 1) + beginVal;
},
easeInOut: function(currTime, beginVal, changeVal, duration, s) {
if (typeof s == "undefined") s = 1.70158;
if ((currTime /= duration / 2) < 1) return changeVal / 2 * (currTime * currTime * (((s *= (1.525)) + 1) * currTime - s)) + beginVal;
return changeVal / 2*((currTime -= 2) * currTime * (((s *= (1.525)) + 1) * currTime + s) + 2) + beginVal;
}
},
"Bounce": {
easeIn: function(currTime, beginVal, changeVal, duration) {
return changeVal - commonJS.tween.Bounce.easeOut(duration-currTime, 0, changeVal, duration) + beginVal;
},
easeOut: function(currTime, beginVal, changeVal, duration) {
if ((currTime /= duration) < (1 / 2.75)) {
return changeVal * (7.5625 * currTime * currTime) + beginVal;
} else if (currTime < (2 / 2.75)) {
return changeVal * (7.5625 * (currTime -= (1.5 / 2.75)) * currTime + .75) + beginVal;
} else if (currTime < (2.5 / 2.75)) {
return changeVal * (7.5625 * (currTime -= (2.25 / 2.75)) * currTime + .9375) + beginVal;
} else {
return changeVal * (7.5625 * (currTime -= (2.625 / 2.75)) * currTime + .984375) + beginVal;
}
},
easeInOut: function(currTime, beginVal, changeVal, duration) {
if (currTime < duration / 2) {
return commonJS.tween.Bounce.easeIn(currTime * 2, 0, changeVal, duration) * .5 + beginVal;
} else {
return commonJS.tween.Bounce.easeOut(currTime * 2 - duration, 0, changeVal, duration) * .5 + changeVal * .5 + beginVal;
}
}
}
};
}());
参考
commonJS — 通用方法(for COM)的更多相关文章
- 使用java泛型设计通用方法
泛型是Java SE 1.5的新特性, 泛型的本质是参数化类型, 也就是说所操作的数据类型被指定为一个参数. 因此我们可以利用泛型和反射来设计一些通用方法. 现在有2张表, 一张user表和一张stu ...
- .NET基础架构方法—DataTableToExcel通用方法
p { display: block; margin: 3px 0 0 0; } --> .NET架构基础方法—DataTableToExcel通用方法(NPOI) 今天封装DataTaleTo ...
- DataTable数据赋值给Model通用方法
注:该文属本人原创,今后项目中发现该方法存在BUG会实时更新,转载记得附上原文出处,方便大家获得最新代码. 相信大家在做项目中,经常会根据不同的表new各种不同的Model,当需要对Model进行实例 ...
- 带毫秒的字符转换成时间(DateTime)格式的通用方法
C#自身有更好的方式,Net任意String格式转换为DateTime类型 ====================================================== 原文 ==== ...
- 使用 highchart 绘制柱状图的通用方法与接口
本文给出使用 highchart 绘制柱状图的通用方法与接口, 只要指定相应的数据结构和配置, 就可以直接拿来使用. 一. 数据结构与基本接口 一般绘制图形, 会涉及到较复杂的数据结构, 比如使 ...
- C# 深拷贝通用方法
C#深拷贝通用方法(引用类型的拷贝) /// <summary> /// 深度COPY /// </summary> /// <typeparam name=" ...
- List对象排序的通用方法
转自 @author chenchuang import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Me ...
- js添加事件通用方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- hibernate学习笔记4---HQL、通用方法的抽取实现
一.通用方法的抽取实现 由于hibernate中对增删改查的一切操作都是面向对象的,所以将增删改查抽取成通用方法,以满足不同的表的增删改查操作,简化jdbc代码. 具体例子如下: package cn ...
随机推荐
- 编写shell管理脚本(一)
7.1 查看当前linux系统中能够使用的shell程序的列表[root@localhost ~]# cat /etc/shells/bin/sh/bin/bash/sbin/nologin/bin ...
- Linux下常用的shell命令记录1
硬件篇 CPU相关 lscpu #查看的是cpu的统计信息. cat /proc/cpuinfo #查看CPU信息详细信息,如每个CPU的型号,主频等 内存相关 free -m #概要查看内存情况 ...
- wifi漫游测试过程
欢迎加入Wince技术讨论群QQ#326444254 这个是我最近测试wifi漫游的一些方法,后续会继续更新,让大家了解测试wifi漫游的方法,由于现在支持wince wifi驱动的厂家非常少,所以支 ...
- UVA 1424 二 Salesmen
Salesmen Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pr ...
- Excel2003命令栏操作
Excel2003个人觉得应该把它抛掉不管了,但还是没忍住想看下它里面的东东. 一.先列出一些重要对象 Commandbars:命令栏集合 ...
- 通过数据库和EasyUI的combobox级联实现省市区三级联动
1.新建一个web项目 2.因为这里用到了数据库所以我们在lib目录导入Hibernate的jar包.fastjson.jar包及数据库jar包 3.同样导入EasyUI的组件配置,并在新建的html ...
- Beaglebone Black - 准备
首先要玩 BBB,你需要买一台 BBB,淘宝 Element14 Beaglebone Black,我购入价 RMB 310,带数据线,没电源适配器的.Seeedstudio 有台叫 Beaglebo ...
- ZOJ 3819 Average Score(平均分)
Description 题目描述 Bob is a freshman in Marjar University. He is clever and diligent. However, he is n ...
- factory工厂模式之工厂方法FactoryMethod
工厂方法(Factory Method) * 工厂方法把不同的产品放在实现了工厂接口的不同工厂类(FactoryAImpl,FactoryBImpl...)里面, * 这样就算其中一个工厂类出了问题, ...
- C#中Application.DoEvents()的作用
Visual Studio里的摘要:处理当前在消息队列中的所有 Windows 消息. 交出CPU控制权,让系统可以处理队列中的所有Windows消息,比如在大运算量循环内,加Application. ...