Commit 75a8afda authored by liuqing's avatar liuqing

1

parent e91a063d
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var arr = [
{ top: '0.4rem', left: '0.5rem' },
{ top: '0.4rem', left: '1.8rem' },
// ... 其他对象 ...
{ top: '2.5rem', left: '0.5rem' },
{ top: '2.5rem', left: '0.5rem' }
];
// 将数组随机排序
arr.sort(function() {
return Math.random() - 0.5;
});
var selectedArr = [];
var part1 = [];
var part2 = [];
var part3 = [];
var numSelected = 0;
// 随机选择7、8、10或12个元素
var numToSelect = [ 12];
var randomNum = Math.floor(Math.random() * 4); // 随机选择7、8、10或12
numSelected = numToSelect[randomNum];
// 将选中的元素分成3个部分
var numPerPart = Math.floor(numSelected / 3);
// 平均从3个数据中选择
var startIndex = 0;
for (var i = 0; i < numSelected; i++) {
var currentPart = i % 3;
if (currentPart === 0) {
part1.push(arr[startIndex + Math.floor(i / 3)]);
} else if (currentPart === 1) {
part2.push(arr[startIndex + Math.floor(i / 3)]);
} else {
part3.push(arr[startIndex + Math.floor(i / 3)]);
}
}
console.log(part1);
console.log(part2);
console.log(part3);
</script>
</body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment