File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ //获取样式信息
3
+ function getStyle ( node , attr ) { //无法取到复合样式 如:border
4
+ if ( node . currentStyle ) { //IE
5
+ return node . currentStyle [ attr ] ;
6
+ } else {
7
+ return getComputedStyle ( node , false ) [ attr ] ;
8
+ }
9
+ }
10
+
11
+ //多属性缓冲运动
12
+ function bufferMove ( obj , json , fn ) {
13
+ clearInterval ( obj . timer ) ;
14
+ obj . timer = setInterval ( function ( ) {
15
+ var state = true ;
16
+ for ( var attr in json ) {
17
+ var iCur = 0 ;
18
+ if ( attr == 'opacity' ) {
19
+ iCur = parseInt ( parseFloat ( getStyle ( obj , attr ) ) * 100 ) ;
20
+ } else {
21
+ iCur = parseInt ( getStyle ( obj , attr ) ) ;
22
+ }
23
+ var iSpeed = ( json [ attr ] - iCur ) / 8 ;
24
+ iSpeed = iSpeed > 0 ? Math . ceil ( iSpeed ) : Math . floor ( iSpeed ) ;
25
+ if ( iCur != json [ attr ] ) {
26
+ state = false ;
27
+ }
28
+ if ( attr == 'opacity' ) {
29
+ obj . alpha = iCur + iSpeed ;
30
+ obj . style . filter = 'alpha(opacity:' + obj . alpha + ')' ;
31
+ obj . style . opacity = obj . alpha / 100 ;
32
+ } else {
33
+ obj . style [ attr ] = iCur + iSpeed + "px" ;
34
+ }
35
+ }
36
+ if ( state ) {
37
+ clearInterval ( obj . timer ) ;
38
+ if ( fn ) { fn ( ) ; }
39
+ }
40
+ } , 30 ) ;
41
+ }
You can’t perform that action at this time.
0 commit comments