2-5 js基础-简易运动框架
2024-09-06 14:13:51
'use strict';
function getStyle(obj,sName){
return (obj.currentStyle||getComputedStyle(obj,false))[sName];
}
//function move(obj,json,time,type,fn)
function move(obj,json,options){
options=options||{};
options.time=options.time||700;
options.type=options.type||'linear';
var start={};
var dis={};
for(var name in json){
start[name]=parseInt(getStyle(obj,name));
if(isNaN(start[name])){
//加默认值
switch(name){
case 'left':
start[name]=obj.offsetLeft;
break;
case'top':
start[name]=obj.offsetTop;
break;
case'width':
start[name]=obj.offsetWidth;
break;
case'Height':
start[name]=obj.offsetHeight;
break
case'opacity':
start[name]=1;
break;
case'border':
start[name]=0;
}
}
dis[name]=json[name]-start[name];
}
var count=Math.floor(options.time/30);
var n=0;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
n++;
var ocr='';
for(var name in json){ switch(options.type){
case'linear':
var a=n/count;
ocr=start[name]+a*dis[name];
break;
case'ease-in':
var a=n/count;
ocr=start[name]+Math.pow(a,3)*dis[name];
break;
case'ease-out':
var a=(1-n/count);
ocr=start[name]+(1-Math.pow(a,3))*dis[name];
break;
}
if(name=='opacity'){
obj.style[name]=ocr;
obj.style[name]='filter:alpha(opacity='+ocr*100+')';
}else{
obj.style[name]=ocr+'px';
}
}
if(n==count){
clearInterval(obj.timer);
options.end&&options.end();
}
},30);
}
最新文章
- mac包管理器Homebrew安装命令
- Centos7下安装python,查看python版本
- .NET Attributes
- Oracle AWR 数据导入/导出的步骤
- 7zip ubuntu使用
- 如何实现phpcms v9_4X版本tag的伪静态?
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能(备用)
- struts2操作pojo之小工程struts2ActionPOJO
- Geodatabase - 打开数据库(工作空间)
- Web安全技术(3)-浏览器的跨域访问
- CSS学习笔记二:css 画立体图形
- Netty开发redis客户端,Netty发送redis命令,netty解析redis消息
- leetcode数据库题目及答案汇总
- k8s初始化搭建方法
- CNZZ友盟访问明细的采集办法
- Android手机上浏览器不支持带端口号wss解决方案
- Oracle用户密码认证方式
- servet概述
- 6、JVM--类文件结构(上)
- Hbase 学习(六) 配置文件调优
热门文章
- vs2008快捷键极其技巧
- Spring AOP详解(转载)
- C# 调用Delphi dll
- rpm包的安装,查询,卸载,升级,校验,数据库重建,验证数据包
- [Cocos2d-x for WP8学习笔记] 获取系统字体
- 【Asp.net MVC】AJAXHelper 和jQueryAjax
- Codeforces Gym 100513F F. Ilya Muromets 水题
- canvas绘制五角星详细过程
- eclipse的classpath(build path)和classpaht几种设置的方式
- delphi 10.2 ----简单的递归函数例子求和