javascript-运动框架
来源:互联网 发布:淘宝店铺名字大全女装 编辑:程序博客网 时间:2024/09/21 09:25
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
function move(obj,json,fn){
var sport=true;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
//取当前的值
for(var attr in json){
if(attr=="opacity"){
var val=Math.round(parseFloat(getStyle(obj,attr))*100);
}else{
var val=parseInt(getStyle(obj,attr));
}
//计算速度
var speed=(json[attr]-val)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//检测停止
if(val!=json[attr]){ //检测是否所有运动都完成
sport=false;
}
if(attr=="opacity"){
obj.style[attr]=(val+speed)/100;
obj.style.filter="alpha(opacity="+(val+speed)+")";
}else{
obj.style[attr]=val+speed+"px";
}
if(sport){
clearInterval(obj.timer);
if(fn){
fn();
}
}
}
},30)
}
-----------------------------------------------------------------------
之前的版本
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
function move(obj,attr,iTarget,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
//取当前的值
if(attr=="opacity"){
var val=Math.round(parseFloat(getStyle(obj,attr))*100);
}else{
var val=parseInt(getStyle(obj,attr));
}
//计算速度
var speed=(iTarget-val)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//检测停止
if(val==iTarget){
clearInterval(obj.timer);
if(fn){
fn();
}
}else{
if(attr=="opacity"){
obj.style[attr]=(val+speed)/100;
obj.style.filter="alpha(opacity="+(val+speed)+")";
}else{obj.style[attr]=val+speed+"px";}
}
},30)
}
0 0
- JavaScript 运动框架
- JavaScript运动框架
- javascript-运动框架
- javascript运动框架---1
- JavaScript 运动框架
- JavaScript - 完美运动框架
- javascript完美运动框架
- javascript中的运动框架
- javascript运动框架---2--缓冲运动
- javascript运动框架多物体运动---1
- javascript运动框架多物体运动---1
- JavaScript运动框架(五):链式运动到完美运动
- javascript运动框架---3--匀速运动
- JavaScript运动框架(全)
- Javascript运动概念2——多物体运动框架
- JavaScript运动框架(三):多物体任意值运动
- JavaScript运动框架(四):多值运动
- JavaScript 运动框架 Step by step
- my vim .vimrc
- Hbase(3):HBase常用shell
- 几种常见数据库简介
- HDU 1016--Prime Ring Problem【DFS】
- 运算符重载详解
- javascript-运动框架
- 就一个快速排序。。。
- 标准C++中的string类的用法总结
- Android 经验分享
- HDU 1180 诡异的楼梯
- C#第一个应用程序
- GOF23设计模式之组合模式的理解
- java 多线程之CountDownLatch用法
- hdu 1203 I NEED A OFFER!