index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <link rel="icon" href="/favicon.ico" />
  6. <meta name="viewport"
  7. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">
  8. <meta http-equiv="Cache-control" content="no-cache">
  9. <meta http-equiv="Cache" content="no-cache">
  10. <meta name="apple-mobile-web-app-capable" content="yes" />
  11. <title>点名</title>
  12. <link rel="stylesheet" href="./css/index.css">
  13. <script src="js/three.min.js"></script>
  14. <script src="js/tween.min.js"></script>
  15. <!-- <script src="js/stats.min.js"></script> -->
  16. <script src="js/TrackballControls.js"></script>
  17. <script src="js/CSS3DRenderer.js"></script>
  18. <script src="js/vue.min.js"></script>
  19. <!-- 创建星星 -->
  20. <!-- <script src="js/star.js"></script> -->
  21. <!-- 数据位置 -->
  22. <script src="js/data.js"></script>
  23. </head>
  24. <body>
  25. <div id="container" style="pointer-events: none;"></div>
  26. <div id="vueBoxs">
  27. <div class="bss" @dblclick="()=>{animationStatus?closes():start()}">
  28. <div class="pageTitle"></div>
  29. <div v-if="platform!=='modal'" class="iconBack" @click.stop="onBack()"></div>
  30. <div id="menu" :class="[platform==='modal'?(imagePos==='right'?'menuRight':'menuLeft'):'']">
  31. <div v-if="platform==='modal' && imagePos==='right'" key="btns">
  32. <div v-if="platform==='modal'" id="backBtn" @click.stop="onBack()"></div>
  33. <div id="sphere" v-show="animationStatus" @click.stop="closes()"></div>
  34. <div id="table" :class="tableIndex <= 1 ? 'disabled' : ''" v-show="!animationStatus"
  35. @click.stop="start()"></div>
  36. </div>
  37. <div v-else key="btns">
  38. <div id="table" :class="tableIndex <= 1 ? 'disabled' : ''" v-show="!animationStatus"
  39. @click.stop="start()"></div>
  40. <div id="sphere" v-show="animationStatus" @click.stop="closes()"></div>
  41. <div v-if="platform==='modal'" id="backBtn" @click.stop="onBack()"></div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </body>
  47. </html>
  48. <script>
  49. var table = getData();
  50. var tableLens = table.length;
  51. var camera, scene, renderer;
  52. var controls;
  53. var objects = [];
  54. var targets = { chaos: [], table: [], sphere: [], helix: [], grid: [] };
  55. var ang = 0, moving = false, objectsss, starBG, isMoving = false; //objectsss 为切换的图片的
  56. var cpx = 0, cpy = 0, cpz = 0, crx = 0, cry = 0, crz = 0;
  57. function init() {
  58. camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
  59. camera.position.z = 1500;
  60. scene = new THREE.Scene();
  61. // table
  62. for (var i = 0; i < table.length; i++) {
  63. // 每个图标的盒子
  64. var element = document.createElement('div');
  65. element.className = 'element';
  66. element.style.backgroundColor = 'rgba(255,255,255)';
  67. element.style.borderRadius = '12px'
  68. if (i >= 32) {
  69. element.className = 'element hide'
  70. }
  71. // 图片
  72. var symbolBox = document.createElement('div');
  73. var symbol = document.createElement('img');
  74. symbolBox.className = 'symbolBox';
  75. symbol.className = 'symbol';
  76. symbol.src = table[i].img;
  77. symbolBox.appendChild(symbol);
  78. element.appendChild(symbolBox);
  79. // 姓名
  80. var details = document.createElement('div');
  81. details.className = 'details';
  82. details.innerHTML = table[i].name;
  83. element.appendChild(details);
  84. // 图标变成3d内的对象,放入场景中
  85. var object = new THREE.CSS3DObject(element);
  86. object.position.x = Math.random() * 3400 - 1700;
  87. object.position.y = Math.random() * 3400 - 1700;
  88. object.position.z = Math.random() * 3400 - 1700;
  89. object.name = table[i].name;
  90. scene.add(object);
  91. objects.push(object);
  92. // 根据索引,定制位置
  93. var object = new THREE.Object3D();
  94. var ix = (i) % 8;
  95. object.position.y = 300;
  96. if (table.length === 1) {
  97. object.position.x = 0;
  98. } else if (table.length === 2) {
  99. object.position.x = (ix * 172) - (172 * 1 / 2);
  100. } else if (table.length === 3) {
  101. object.position.x = (ix * 172) - (172 * 2 / 2);
  102. } else if (table.length === 4) {
  103. object.position.x = (ix * 172) - (172 * 3 / 2);
  104. } else if (table.length === 5) {
  105. object.position.x = (ix * 172) - (172 * 4 / 2);
  106. } else if (table.length === 6) {
  107. object.position.x = (ix * 172) - (172 * 5 / 2);
  108. } else if (table.length === 7) {
  109. object.position.x = (ix * 172) - (172 * 6 / 2);
  110. } else {
  111. var iy = Math.floor((i) / 8);
  112. object.position.x = (ix * 172) - 600;
  113. object.position.y = - (iy * 192) + 300;
  114. }
  115. targets.table.push(object);
  116. }
  117. // 创建切换图片
  118. var elements = document.createElement('div');
  119. elements.className = 'changeImgBoxs';
  120. // element.style.backgroundImage = "url(./img/pic.png)";
  121. elements.style.backgroundColor = 'rgba(255,255,255)';
  122. var symbolBox = document.createElement('div');
  123. var symbol = document.createElement('img');
  124. symbol.setAttribute("id", "changeImg");
  125. symbolBox.className = 'symbolBox2';
  126. symbol.className = 'symbol2';
  127. symbol.src = table[0].img;
  128. symbolBox.appendChild(symbol);
  129. elements.appendChild(symbolBox);
  130. var details = document.createElement('div');
  131. details.setAttribute("id", "detailss");
  132. details.className = 'details';
  133. details.innerHTML = table[0].name;
  134. elements.appendChild(details);
  135. objectsss = new THREE.CSS3DObject(elements);
  136. objectsss.position.x = 0;
  137. objectsss.position.y = 20000;
  138. objectsss.position.z = 0;
  139. scene.add(objectsss);
  140. // 散乱随机位置
  141. var vector = new THREE.Vector3();
  142. for (var i = 0, l = objects.length; i < l; i++) {
  143. var phi = Math.acos(-1 + (2 * i) / l);
  144. var theta = Math.sqrt(l * Math.PI) * phi;
  145. var object = new THREE.Object3D();
  146. var py = Math.random() * 3400 - 1700;
  147. if (py < 400 && py > -400) { //防止停止时,图片位置不好挡住中央的图片
  148. if (py < 0) {
  149. py -= 400;
  150. } else {
  151. py += 400;
  152. }
  153. }
  154. object.position.x = Math.random() * 3400 - 1700;
  155. object.position.y = py;
  156. object.position.z = Math.random() * 3400 - 1700;
  157. object.lookAt(vector);
  158. targets.chaos.push(object);
  159. }
  160. // 球
  161. var vector = new THREE.Vector3();
  162. for (var i = 0, l = objects.length; i < l; i++) {
  163. var phi = Math.acos(-1 + (2 * i) / l);
  164. var theta = Math.sqrt(l * Math.PI) * phi;
  165. var object = new THREE.Object3D();
  166. object.position.x = 750 * Math.cos(theta) * Math.sin(phi);
  167. object.position.y = 750 * Math.sin(theta) * Math.sin(phi);
  168. object.position.z = 750 * Math.cos(phi);
  169. vector.copy(object.position).multiplyScalar(2);
  170. object.lookAt(vector);
  171. targets.sphere.push(object);
  172. }
  173. //渲染
  174. renderer = new THREE.CSS3DRenderer();
  175. renderer.setSize(window.innerWidth, window.innerHeight);
  176. renderer.domElement.style.position = 'absolute';
  177. document.getElementById('container').appendChild(renderer.domElement);
  178. //控制器
  179. controls = new THREE.TrackballControls(camera, renderer.domElement);
  180. controls.rotateSpeed = 0.5;
  181. controls.minDistance = 500;
  182. controls.maxDistance = 6000;
  183. controls.addEventListener('change', render);
  184. // 初始化
  185. transform(targets.table, 500);
  186. window.addEventListener('resize', onWindowResize, false);
  187. cpx = camera.position.x;
  188. cpy = camera.position.y;
  189. cpz = camera.position.z;
  190. crx = camera.rotation.x;
  191. cry = camera.rotation.y;
  192. crz = camera.rotation.z;
  193. }
  194. // 切换状态时动画
  195. function transform(targets, duration, type) {
  196. var scale = 1;
  197. if (type == undefined) {
  198. type = 0;
  199. }
  200. TWEEN.removeAll();
  201. for (var i = 0; i < objects.length; i++) {
  202. var object = objects[i];
  203. var target = targets[i];
  204. new TWEEN.Tween(object.position)
  205. .to({ x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration)
  206. .easing(TWEEN.Easing.Exponential.InOut)
  207. .start();
  208. new TWEEN.Tween(object.rotation)
  209. .to({ x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration)
  210. .easing(TWEEN.Easing.Exponential.InOut)
  211. .start();
  212. }
  213. new TWEEN.Tween(this)
  214. .to({}, duration * 2)
  215. .onUpdate(render)
  216. .start()
  217. // console.log(document.querySelectorAll('.element'), '1212')
  218. setTimeout(() => {
  219. if (moving || type === 2) {
  220. const elements = document.querySelectorAll('.element')
  221. if (elements.length > 0) {
  222. elements.forEach((e, index) => {
  223. if (type === 2) {
  224. if (index >= 32) {
  225. e.classList.add('hide')
  226. }
  227. } else {
  228. e.classList.remove('hide')
  229. }
  230. })
  231. }
  232. }
  233. }, 400);
  234. }
  235. // 屏幕大小适配
  236. function onWindowResize() {
  237. camera.aspect = window.innerWidth / window.innerHeight;
  238. camera.updateProjectionMatrix();
  239. renderer.setSize(window.innerWidth, window.innerHeight);
  240. render();
  241. }
  242. function animate() {
  243. requestAnimationFrame(animate);
  244. TWEEN.update();
  245. // 旋转
  246. if (moving) {
  247. movings();
  248. }
  249. controls.update();
  250. // 星空位置与相机位置相对
  251. cpx = camera.position.x;
  252. cpy = camera.position.y;
  253. cpz = camera.position.z;
  254. crx = camera.rotation.x;
  255. cry = camera.rotation.y;
  256. crz = camera.rotation.z;
  257. }
  258. function render() {
  259. renderer.render(scene, camera);
  260. }
  261. var numsss = 0, srcss = '', txtsss = '';
  262. function movings() {
  263. // 相机旋转
  264. ang += Math.PI / 50;
  265. camera.position.x = Math.cos(ang) * 2000;
  266. camera.position.z = Math.sin(ang) * 2000;
  267. camera.position.y = 0;
  268. // 相机方向重置
  269. camera.up.x = 0;
  270. camera.up.y = 1;
  271. camera.up.z = 0;
  272. // 图片方向固定
  273. objectsss.rotation.y = -ang + Math.PI / 2;
  274. //中间图片切换
  275. numsss = Math.floor(Math.random() * tableLens);
  276. if (numsss == tableLens) {
  277. numsss = tableLens - 1;
  278. }
  279. srcss = table[numsss].img;
  280. txtsss = table[numsss].name;
  281. changeImg.src = srcss;
  282. detailss.innerHTML = txtsss;
  283. }
  284. // 停止时,图片放大动画
  285. function objDeal(obj, nums) {
  286. var option = {
  287. x: obj.scale.x,
  288. y: obj.scale.y,
  289. z: obj.scale.z,
  290. };
  291. var tween = new TWEEN.Tween(option).to({
  292. x: nums,
  293. y: nums,
  294. z: nums,
  295. }, 300).delay(100).onUpdate(function () {
  296. obj.scale.x = this.x;
  297. obj.scale.y = this.y;
  298. obj.scale.z = this.z;
  299. isMoving = true;
  300. }).onComplete(function () {
  301. isMoving = false;
  302. }).start();
  303. }
  304. // 初始化数据
  305. function renderData(data) {
  306. table = data
  307. tableLens = data.length
  308. vm.tableIndex = tableLens
  309. init();
  310. animate();
  311. console.log(vm.tableIndex, 'renderData')
  312. }
  313. //点击事件及部分判断
  314. var vm = new Vue({
  315. el: '#vueBoxs',
  316. data: {
  317. animationStatus: false,
  318. tableIndex: 0,
  319. listShow: false,
  320. platform: "",
  321. imagePos: ""
  322. },
  323. methods: {
  324. keyDowns: function () {
  325. this.closes();
  326. },
  327. //开始
  328. start: function () {
  329. if (this.tableIndex <= 1) {
  330. return
  331. }
  332. moving = true;
  333. this.animationStatus = true;
  334. objectsss.position.y = 0;
  335. transform(targets.sphere, 1000);
  336. objDeal(objectsss, 1);
  337. // music.play();
  338. // this.ckPrice();
  339. },
  340. //结束
  341. closes: function () {
  342. // music.pause();
  343. if (!moving) {
  344. return;
  345. }
  346. // music2.play();
  347. moving = false;
  348. this.animationStatus = false;
  349. // this.choosePerson();
  350. transform(targets.chaos, 250, 1);
  351. objDeal(objectsss, 1.8);
  352. },
  353. //回到照片墙的状态
  354. resets: function () {
  355. moving = false;
  356. camera.position.z = 1500;
  357. camera.position.x = 0;
  358. camera.position.y = 0;
  359. camera.up.x = 0;//相机以哪个方向为上方
  360. camera.up.y = 1;
  361. camera.up.z = 0;
  362. //图片重置方向
  363. objectsss.rotation.y = 0;
  364. objectsss.position.y = 20000;
  365. objectsss.scale.set(1, 1, 1);
  366. // 星空背景图重置
  367. transform(targets.table, 400, 2);
  368. // music.pause();
  369. // this.ckPrice();
  370. },
  371. onBack() {
  372. // 返回时先结束
  373. this.closes()
  374. this.resets()
  375. window.parent.postMessage({
  376. api: 'callBack',
  377. loading: false,
  378. }, '*');
  379. },
  380. handleUrlParmas(){
  381. const params=getUrlParams(location.href)
  382. params?.platform&&(this.platform = params?.platform)
  383. params?.imagePos&&(this.imagePos = params?.imagePos)
  384. }
  385. },
  386. created: function () {
  387. // init();
  388. // animate();
  389. // getStar();
  390. // this.ckPrice();
  391. this.handleUrlParmas()
  392. }
  393. })
  394. function getUrlParams(url) {
  395. let urlStr = url.split('?')[1]
  396. const urlSearchParams = new URLSearchParams(urlStr)
  397. const result = Object.fromEntries(urlSearchParams.entries())
  398. return result
  399. }
  400. </script>