index.html 13 KB

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