-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
42 lines (37 loc) · 946 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function moveTo( e, l )
{
var speed = 1;
var initTime = 30;
(function f () {
var time = 0;
var left = parseInt( getStyle( e, "left" ) );
//console.debug( e.style.left );
//console.debug( left );
if ( left < l ){
e.style.left = left + speed;
}
else if ( left > l ){
e.style.left = left - speed;
}
else{
return;
}
//console.debug( e.style.left );
time = Math.max( 0, initTime - Math.abs( l - parseInt( e.style.left ) ) );
//console.debug( time );
setTimeout( f, time );
})();
}
function getStyle(oElm, strCssRule){
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
}
else if(oElm.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
return p1.toUpperCase();
});
strValue = oElm.currentStyle[strCssRule];
}
return strValue;
}