index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <!DOCTYPE html>
  2. <head>
  3. <title>恒硕科技产业园</title>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  6. <meta id="jdouview" name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
  7. <meta name="format-detection" content="telephone=no">
  8. <style>
  9. body {
  10. background-color: #000000;
  11. margin: 0;
  12. cursor: move;
  13. overflow: hidden;
  14. }
  15. .bg_section {
  16. width: 1026px;
  17. height: 1026px;
  18. background-size: cover;
  19. position: absolute;
  20. }
  21. .bg_section .bg {
  22. position: absolute;
  23. width: 1026px;
  24. height: 1026px;
  25. }
  26. .btn1 {
  27. position: absolute;
  28. width: 74px;
  29. height: 96px;
  30. top: 20%;
  31. left: 40%;
  32. -webkit-transform: perspective(600px);
  33. background: url("images/btn1.png");
  34. background-size: 100% 100%;
  35. }
  36. .btn2 {
  37. position: absolute;
  38. width: 71px;
  39. height: 91px;
  40. top: 30%;
  41. left: 50%;
  42. -webkit-transform: perspective(600px);
  43. background: url("images/btn2.png");
  44. background-size: 100% 100%;
  45. }
  46. .controlBtn {
  47. width: 60px;
  48. height: 60px;
  49. position: fixed;
  50. z-index: 99999;
  51. left: 8%;
  52. top: 5%;
  53. }
  54. .controlIcon {
  55. background: url("images/controlIcon.png");
  56. background-size: 100% 100%;
  57. }
  58. .controlIconae {
  59. background: url("images/controlIconae.png");
  60. background-size: 100% 100%;
  61. }
  62. @-webkit-keyframes bounceant1 {
  63. 0% {
  64. -webkit-transform: translateY(0)
  65. }
  66. 50% {
  67. -webkit-transform: translateY(-12px)
  68. }
  69. 100% {
  70. -webkit-transform: translateY(0px)
  71. }
  72. }
  73. @keyframes bounceant1 {
  74. 0% {
  75. transform: translateY(0)
  76. }
  77. 50% {
  78. transform: translateY(-12px)
  79. }
  80. 100% {
  81. transform: translateY(0px)
  82. }
  83. }
  84. .bounceant1 {
  85. -webkit-animation: bounceant1 3s infinite;
  86. animation: bounceant1 3s infinite
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <!-- <div id="controlBtn" class="controlBtn controlIconae"></div> -->
  92. <!-- 陀螺仪开启按钮 -->
  93. <div id="pano">
  94. <!-- 正方体的六个面 -->
  95. <div id="bg_section_0" class="bg_section bg_section_4 scale_test">
  96. <img class="bg" src="images/pic.right.jpg">
  97. <!-- <div class="btn1 bounceant1"></div> -->
  98. <!-- 可点击按钮1 -->
  99. </div>
  100. <div id="bg_section_1" class="bg_section bg_section_5 scale_test">
  101. <img class="bg" src="images/pic.left.jpg">
  102. </div>
  103. <div id="bg_section_2" class="bg_section bg_section_2 scale_test">
  104. <img class="bg" src="images/pic.top.jpg">
  105. </div>
  106. <div id="bg_section_3" class="bg_section bg_section_3 scale_test">
  107. <img class="bg" src="images/pic.bottom.jpg">
  108. </div>
  109. <div id="bg_section_4" class="bg_section bg_section_1 scale_test">
  110. <img class="bg" src="images/pic.front.jpg">
  111. <!-- <div class="btn2 bounceant1"></div> -->
  112. <!-- 可点击按钮2 -->
  113. </div>
  114. <div id="bg_section_5" class="bg_section bg_section_0 scale_test">
  115. <img class="bg" src="images/pic.back.jpg">
  116. </div>
  117. </div>
  118. <script src="js/zepto.min.js"></script>
  119. <script src="js/three.min.js"></script>
  120. <script src="js/CSS3DRenderer.min.js"></script>
  121. <script src="js/DeviceOrientationControls.js"></script>
  122. <script>
  123. var camera, scene, renderer;
  124. var geometry, material, mesh;
  125. var target = new THREE.Vector3();
  126. var lon = 266.59, lat = -18.99;
  127. var phi = 0, theta = 0;
  128. var touchX, touchY;
  129. init();
  130. animate();
  131. function init() {
  132. /**
  133. * 添加相机
  134. * @type {THREE.PerspectiveCamera}
  135. */
  136. camera = new THREE.PerspectiveCamera(
  137. 98, // 相机视角的夹角
  138. window.innerWidth / window.innerHeight, // 相机画幅比
  139. 1, // 最近焦距
  140. 1000 // 最远焦距
  141. );
  142. /**
  143. * 创建场景
  144. * @type {THREE.Scene}
  145. */
  146. scene = new THREE.Scene();
  147. /**
  148. *正方体的6个面的资源及相关(坐标、旋转等)设置
  149. */
  150. var flipAngle = Math.PI, // 180度
  151. rightAngle = flipAngle / 2, // 90度
  152. tileWidth = 512;
  153. var sides = [{
  154. url: "images/panorama.right.jpg",
  155. position: [-tileWidth, 0, 0],
  156. rotation: [0, rightAngle, 0]
  157. }, {
  158. url: "images/panorama.left.jpg",
  159. position: [tileWidth, 0, 0],
  160. rotation: [0, -rightAngle, 0]
  161. }, {
  162. url: "images/panorama.top.jpg",
  163. position: [0, tileWidth, 0],
  164. rotation: [rightAngle, 0, Math.PI]
  165. }, {
  166. url: "images/panorama.bottom.jpg",
  167. position: [0, -tileWidth, 0],
  168. rotation: [-rightAngle, 0, Math.PI]
  169. }, {
  170. url: "images/panorama.front.jpg",
  171. position: [0, 0, tileWidth],
  172. rotation: [0, Math.PI, 0]
  173. }, {
  174. url: "images/panorama.back.jpg",
  175. position: [0, 0, -tileWidth],
  176. rotation: [0, 0, 0]
  177. }];
  178. for (var i = 0; i < sides.length; i++) {
  179. var side = sides[i];
  180. var element = document.getElementById("bg_section_" + i);
  181. element.width = 1026;
  182. element.height = 1026; // 2 pixels extra to close the gap.
  183. // 添加一个渲染器
  184. var object = new THREE.CSS3DObject(element);
  185. object.position.fromArray(side.position);
  186. object.rotation.fromArray(side.rotation);
  187. scene.add(object);
  188. }
  189. renderer = new THREE.CSS3DRenderer(); // 定义渲染器
  190. renderer.setSize(window.innerWidth, window.innerHeight); // 定义尺寸
  191. document.body.appendChild(renderer.domElement); // 将场景到加入页面中
  192. initDevices();
  193. initMouseControl();
  194. }
  195. // 初始化控制器
  196. function initMouseControl() {
  197. // mouseControl = new THREE.OrbitControls(camera);
  198. document.addEventListener('mousedown', onDocumentMouseDown, false);
  199. document.addEventListener('wheel', onDocumentMouseWheel, false);
  200. document.addEventListener('touchstart', onDocumentTouchStart, false);
  201. document.addEventListener('touchmove', onDocumentTouchMove, false);
  202. window.addEventListener('resize', onWindowResize, false);
  203. }
  204. var controlsBtn = document.getElementById("controlBtn"); // 控制陀螺仪开关的按钮
  205. var isDeviceing = false; // 陀螺仪状态
  206. controlsBtn.addEventListener("touchend", controlDevice, true);
  207. isDeviceing == true ? $("#controlBtn").addClass("controlIconae") : $("#controlBtn").addClass("controlIcon");
  208. // 初始化陀螺仪
  209. function initDevices() {
  210. deviceControl = new THREE.DeviceOrientationControls(camera);
  211. }
  212. /* 控制陀螺仪 */
  213. function controlDevice(event) {
  214. if (isDeviceing == true) {
  215. isDeviceing = false;
  216. //关闭陀螺仪
  217. $("#controlBtn").removeClass("controlIcon").addClass("controlIconae");
  218. } else {
  219. isDeviceing = true;
  220. //开启陀螺仪
  221. $("#controlBtn").removeClass("controlIconae").addClass("controlIcon");
  222. }
  223. }
  224. /**
  225. * 窗体大小改变
  226. */
  227. function onWindowResize() {
  228. camera.aspect = window.innerWidth / window.innerHeight;
  229. camera.updateProjectionMatrix();
  230. renderer.setSize(window.innerWidth, window.innerHeight);
  231. }
  232. /*
  233. 相机焦点跟着鼠标或手指的操作移动
  234. */
  235. function onDocumentMouseDown(event) {
  236. event.preventDefault();
  237. document.addEventListener('mousemove', onDocumentMouseMove, false);
  238. document.addEventListener('mouseup', onDocumentMouseUp, false);
  239. }
  240. function onDocumentMouseMove(event) {
  241. var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
  242. var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
  243. lon -= movementX * 0.1;
  244. lat += movementY * 0.1;
  245. }
  246. function onDocumentMouseUp(event) {
  247. document.removeEventListener('mousemove', onDocumentMouseMove);
  248. document.removeEventListener('mouseup', onDocumentMouseUp);
  249. }
  250. /**
  251. * 鼠标滚轮改变相机焦距
  252. */
  253. function onDocumentMouseWheel(event) {
  254. camera.fov += event.deltaY * 0.05;
  255. console.log("#debug#🚀 ~ file: index.html:295 ~ onDocumentMouseWheel ~ camera.fov:", camera.fov)
  256. camera.updateProjectionMatrix();
  257. }
  258. function onDocumentTouchStart(event) {
  259. event.preventDefault();
  260. var touch = event.touches[0];
  261. touchX = touch.screenX;
  262. touchY = touch.screenY;
  263. }
  264. function onDocumentTouchMove(event) {
  265. event.preventDefault();
  266. var touch = event.touches[0];
  267. lon -= (touch.screenX - touchX) * 0.2;
  268. lat += (touch.screenY - touchY) * 0.2;
  269. console.log("#debug#🚀 ~ file: index.html:310 ~ onDocumentTouchMove ~ lon:", lon)
  270. console.log("#debug#🚀 ~ file: index.html:312 ~ onDocumentTouchMove ~ lat:", lat)
  271. touchX = touch.screenX;
  272. touchY = touch.screenY;
  273. }
  274. /**
  275. * 实时渲染函数
  276. */
  277. function animate() {
  278. requestAnimationFrame(animate);
  279. // lon = Math.max(-180, Math.min(180, lon));//限制固定角度内旋转
  280. // lon += 0.1;//自动旋转
  281. lat = Math.max(-85, Math.min(85, lat)); //限制固定角度内旋转
  282. phi = THREE.Math.degToRad(85 - lat);
  283. theta = THREE.Math.degToRad(lon + 180);
  284. target.x = Math.sin(phi) * Math.cos(theta);
  285. target.y = Math.cos(phi);
  286. target.z = Math.sin(phi) * Math.sin(theta);
  287. camera.lookAt(target);
  288. camera.updateProjectionMatrix();
  289. isDeviceing == false ? initMouseControl() : deviceControl.update();
  290. renderer.render(scene, camera);
  291. }
  292. $('.btn1').on('click', function () {
  293. alert('第一个按钮被点击了');
  294. });
  295. $('.btn2').on('click', function () {
  296. alert('第二个按钮被点击了');
  297. });
  298. </script>
  299. </body>
  300. </html>