JSDM

HTML

 
1
<div id="container"></div>

CSS

xxxxxxxxxx
20
 
1
* {
2
    box-sizing: border-box;
3
}
4
body {
5
    background-color: #242424;
6
}
7
#container {
8
    height: 300px;
9
    width: 300px;
10
    position: absolute;
11
    top: calc(50% - 150px);
12
    left: calc(50% - 150px);
13
}
14
.box {
15
    display: inline-block;
16
    height: 9px;
17
    width: 9px;
18
    position: absolute;
19
   
20
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

x
 
1
var df = document.createDocumentFragment();
2
var container = document.getElementById('container');
3
for (var i = 0; i < 900; i++) {
4
    var x = i % 30;
5
    var y = ~~ (i / 30);
6
    var elm = document.createElement('div');
7
    elm.className = 'box';
8
    elm.style.top = (y * 10) + 'px';
9
    elm.style.left = (x * 10) + 'px';
10
    elm.style.backgroundColor = color(x%y+y%x);
11
    df.appendChild(elm);
12
}
13
container.appendChild(df);
14
var cycle = 0;
15
var children = container.children;
16
run();
17
18
function run() {
19
    requestAnimationFrame(run);
20
    for (var i = 0, l = children.length; i < l; i++) {
21
        var top = parseFloat(children[i].style.top);
22
        var left = parseFloat(children[i].style.left);
23
        children[i].style.top = top + Math.cos(cycle + (i % 30)) + 'px';
24
        children[i].style.left = left + Math.sin(cycle + ~~ (i / 30)) + 'px';
25
        cycle += 1e-4;
26
    }
27
}
28
function color(i) {
29
    var r = Math.floor( Math.sin(i) * 127 + 128 );
30
    var g = Math.floor( Math.sin(i + 2) * 127 + 128 );
31
    var b = Math.floor( Math.sin(i + 3) * 127 + 128 );
32
    return 'rgb(' + r + ', ' + g + ',' + b + ')';
33
}
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................