1
- < html > < head >
2
- < meta charset ="UTF-8 ">
3
- < meta name ="viewport " content ="width=device-width, minimum-scale=1.0 ">
4
- < title > Unim.js</ title >
5
- < style >
6
- # container {
7
- width : 200px ;
8
- height : auto;
9
- margin : 0 auto;
10
- position : relative;
11
- display : block;
12
- }
13
-
14
- .line {
15
- width : 200px ;
16
- height : 2px ;
17
- position : absolute;
18
- }
19
- </ style >
20
- </ head >
21
- < body >
1
+ < html >
22
2
23
- < div id ="container "> </ div >
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, minimum-scale=1.0 ">
6
+ < title > TWEEN.js</ title >
7
+ < style >
8
+ # container {
9
+ width : 200px ;
10
+ height : auto;
11
+ margin : 0 auto;
12
+ position : relative;
13
+ display : block;
14
+ }
15
+
16
+ .line {
17
+ width : 200px ;
18
+ height : 2px ;
19
+ position : absolute;
20
+ }
21
+ </ style >
22
+ </ head >
24
23
25
- < script src ="../dist/Tween.js "> </ script >
26
- < script >
27
-
28
- TWEEN . autoPlay ( true ) ;
24
+ < body >
29
25
30
- function random ( min , max ) {
31
- return Math . random ( ) * ( max - min ) + min ;
32
- }
26
+ < div id ="container "> </ div >
33
27
34
- var nodes = [ ] ,
35
- c = document . getElementById ( "container" ) ,
36
- easing = "quadraticInOut" ,
37
- wIh = window . innerHeight || screen . height - 40 ,
38
- frag = document . createDocumentFragment ( ) ;
39
-
40
- const update = ( object ) => {
41
- object . dom . style . transform = object . transform ;
42
- }
28
+ < script src ="../dist/Tween.js "> </ script >
29
+ < script >
30
+ TWEEN . autoPlay ( true ) ;
43
31
44
- const Style = TWEEN . Plugins . DOM ;
32
+ function random ( min , max ) {
33
+ return Math . random ( ) * ( max - min ) + min ;
34
+ }
45
35
46
- function createTest ( count ) {
47
- var i ;
48
- for ( i = 0 ; i < count ; i ++ ) {
49
- var div = document . createElement ( "div" ) ,
50
- bg = ( Math . random ( ) * 0xffffff ) >> 0 ,
51
- bgC = "#" + bg . toString ( 16 ) ,
52
- l = Math . floor ( random ( - 200 , 200 ) ) ,
53
- dl = Math . floor ( Math . random ( ) * 1000 ) ,
54
- tl = Math . floor ( random ( - 200 , 200 ) ) ;
55
- div . setAttribute ( "class" , "line" ) ;
56
- div . style . top = [ ( Math . random ( ) * wIh ) , "px" ] . join ( "" ) ;
57
- div . style . transform = "translate3d(" + l + "px, 0px, 0px)" ;
58
- //div.style.left = l + "px";
59
- div . style . backgroundColor = bgC ;
60
- nodes . push ( div ) ;
61
- frag . appendChild ( div ) ;
62
- var layer = new TWEEN . Composite ( div ) . applyPlugin ( 'DOM' ) ;
63
- var a = new TWEEN . Tween ( { transform : `translate3d(${ l } px, 0px, 0px)` , dom :div } ) . to ( {
64
- transform : `translate3d(${ tl } px, 0px, 0px)`
65
- } , 1000 ) . easing ( TWEEN . Easing . Quadratic . InOut ) . on ( 'update' , layer . render ) . repeat ( Infinity ) . yoyo ( true ) . start ( ) ;
36
+ var nodes = [ ] ,
37
+ c = document . getElementById ( "container" ) ,
38
+ easing = "quadraticInOut" ,
39
+ ratio = 0.9 ,
40
+ wIh = ( window . innerHeight || screen . height - 40 ) * ratio ,
41
+ wIw = window . innerWidth ,
42
+ hwiw = ( wIw / 5 ) * ratio ,
43
+ frag = document . createDocumentFragment ( ) ;
66
44
67
- }
68
- c . appendChild ( frag ) ;
69
- }
70
- createTest ( 2 ) ;
71
- </ script >
72
-
73
- </ body > </ html >
45
+ const update = ( object ) => {
46
+ object . dom . style . transform = object . transform ;
47
+ }
48
+
49
+ const Style = TWEEN . Plugins . DOM ;
50
+
51
+ function createTest ( count ) {
52
+ var i ;
53
+ for ( i = 0 ; i < count ; i ++ ) {
54
+ var div = document . createElement ( "div" ) ,
55
+ bg = ( Math . random ( ) * 0xffffff ) >> 0 ,
56
+ bgC = "#" + bg . toString ( 16 ) ,
57
+ l = Math . floor ( random ( - 200 , 200 ) ) ,
58
+ dl = Math . floor ( Math . random ( ) * 1000 ) ,
59
+ tl = Math . floor ( random ( - 200 , 200 ) ) ;
60
+ div . setAttribute ( "class" , "line" ) ;
61
+ div . style . top = [ ( Math . random ( ) * wIh ) , "px" ] . join ( "" ) ;
62
+ div . style . transform = "translate3d(" + - hwiw + "px, 0px, 0px)" ;
63
+ //div.style.left = l + "px";
64
+ div . style . backgroundColor = bgC ;
65
+ var layer = new TWEEN . Composite ( div ) . applyPlugin ( 'DOM' ) ;
66
+ var a = new TWEEN . Tween ( { transform : `translate3d(${ - hwiw } px, 0px, 0px)` } ) . to ( {
67
+ transform : `translate3d(${ hwiw } px, 0px, 0px)`
68
+ } , 1000 ) . easing ( TWEEN . Easing . Circular . InOut ) . on ( 'update' , layer . render ) . repeat ( Infinity ) . yoyo ( true ) ;
69
+ nodes . push ( { layer : layer , node : div , tween : a } ) ;
70
+
71
+ }
72
+ nodes . sort ( ( a , b ) => {
73
+ return parseFloat ( a . node . style . top ) - parseFloat ( b . node . style . top ) ;
74
+ } ) . map ( ( node , i ) => {
75
+ frag . appendChild ( node . node ) ;
76
+ node . tween . delay ( delay => {
77
+ return ( i * ( i % 2 ? 15 : - 15 ) ) ;
78
+ } ) . start ( ) ;
79
+ } )
80
+ c . appendChild ( frag ) ;
81
+ }
82
+ createTest ( 200 ) ;
83
+ </ script >
84
+
85
+ </ body >
86
+
87
+ </ html >
0 commit comments