1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7+ < title > 爱心666</ title >
8+ < style >
9+ html ,
10+ body {
11+ overflow : hidden;
12+ width : 100% ;
13+ height : 100% ;
14+ margin : 0 ;
15+ }
16+
17+ # heart {
18+ position : relative;
19+ }
20+
21+ .item {
22+ position : absolute;
23+ }
24+ </ style >
25+ </ head >
26+
27+ < body >
28+ < div id ="heart ">
29+
30+ </ div >
31+
32+ < script >
33+ let heartList = '' ;
34+ const n = 666 ;
35+ function getRandomColor ( ) {
36+ return ( function ( m , s , c ) {
37+ return ( c ? arguments . callee ( m , s , c - 1 ) : '#' ) +
38+ s [ m . floor ( m . random ( ) * 16 ) ]
39+ } ) ( Math , '0123456789abcdef' , 5 )
40+ }
41+ // 生成爱心列表
42+ for ( let i = 0 ; i <= n ; i ++ ) {
43+ heartList += `
44+ <svg id="heart_${ i } " class="item" t="1587910011145" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1253" width="32" height="32" fill="${ getRandomColor ( ) } "><path d="M677.51936 192.03072c113.1008 0 204.8 91.6992 204.8 204.77952 0 186.91072-370.3296 435.15904-370.3296 435.15904S141.68064 592.67072 141.68064 396.81024c0-140.78976 91.6992-204.77952 204.77952-204.77952 68.11648 0 128.28672 33.40288 165.5296 84.55168C549.24288 225.4336 609.41312 192.03072 677.51936 192.03072z" p-id="1254"></path></svg>
45+ `
46+ }
47+ // 随机放大倍数
48+ const getRandomNum = ( scale ) => Math . floor ( Math . random ( ) * scale + 1 ) ;
49+ const boxWidth = window . innerWidth ;
50+ const boxHeight = window . innerHeight ;
51+ const animateNum = 99 ;
52+ setTimeout ( function ( ) {
53+ for ( let i = 0 ; i <= n ; i ++ ) {
54+ const item = `heart_${ i } ` ;
55+ const width = getRandomNum ( boxWidth ) ;
56+ const height = getRandomNum ( boxHeight ) ;
57+ const cWidth = getRandomNum ( 1000 ) - width ;
58+ const cHeight = getRandomNum ( 1000 ) - height ;
59+ console . log ( cWidth , cHeight )
60+ document . getElementById ( item ) . animate ( [
61+ { transform : `scale(${ getRandomNum ( 2 ) } )` , left : `0px` , top : `0px` } ,
62+ { transform : `scale(${ getRandomNum ( 2 ) } )` , left : `${ boxWidth / 2 } px` , top : `${ boxHeight / 2 } px` } ,
63+ { transform : `scale(${ getRandomNum ( 2 ) } )` , left : `${ cWidth * 2 } px` , top : `${ cHeight * 2 } px` } ,
64+ ] , {
65+ // timing options
66+ duration : 9000 ,
67+ iterations : Infinity ,
68+ easing : 'ease-in-out'
69+ } ) ;
70+ }
71+ } , 100 )
72+ document . getElementById ( 'heart' ) . innerHTML = heartList ;
73+ </ script >
74+ </ body >
75+
76+ </ html >
0 commit comments