default.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <div>
  3. <template v-if="notWebgl">
  4. </template>
  5. <template v-else>
  6. <canvas id="output"></canvas>
  7. <div class="wrapper">
  8. <div class="header">
  9. <span class="logo">NUTUI<s></s></span>
  10. <span class="search"><input type="text" placeholder="在nutui中搜索" class="search-input"/></span>
  11. <div class="meun">
  12. <ul>
  13. <li>指南</li>
  14. <li>组件</li>
  15. <li>示例</li>
  16. </ul>
  17. <select>
  18. <option>
  19. 2.X
  20. </option>
  21. <option>
  22. 1.X
  23. </option>
  24. </select>
  25. <span class="github-icon">
  26. github
  27. </span>
  28. </div>
  29. </div>
  30. <div class="content">
  31. <div class="mouseDiv" id="mouseDiv"></div>
  32. <p class="title">Nut UI</p>
  33. <p class="sub-title">一套具有京东特色的移动端Vue / 微信小程序组件库</p>
  34. <a href="javascript:;" class="blue-btn">开始使用</a><a href="javascript:;" class="btn">扫码体验</a>
  35. </div>
  36. </div>
  37. </template>
  38. </div>
  39. </template>
  40. <script>
  41. import * as THREE from 'three';
  42. import TWEEN from '@tweenjs/tween.js';
  43. import Detector from './asset/js/Detector.js';
  44. export default {
  45. name: "frontCover",
  46. data() {
  47. return{
  48. timer:null,
  49. notWebgl:true,
  50. }
  51. },
  52. methods:{
  53. threeAnimation(){
  54. this.timer = setTimeout(()=>{
  55. //获取视窗宽高
  56. var mouseX = 0,mouseY = 0;
  57. var SCREEN_HEIGHT = window.innerHeight;
  58. var SCREEN_WIDTH = window.innerWidth;
  59. var tween;
  60. var planeObj ={
  61. x:450,
  62. y:80
  63. }
  64. //渲染器(render)
  65. var renderer = new THREE.WebGLRenderer({
  66. canvas:document.getElementById('output')
  67. });
  68. //设置背景颜色
  69. renderer.setClearColor(0xffffff,1.0);
  70. renderer.setPixelRatio(window.devicePixelRatio);
  71. renderer.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
  72. //场景(Scene)
  73. var scene = new THREE.Scene();
  74. //透视投影相机
  75. var camera = new THREE.PerspectiveCamera(45, SCREEN_WIDTH/ SCREEN_HEIGHT, 1, 10000);
  76. camera.position.set(0, 0, 1300);
  77. camera.lookAt( scene.position);
  78. scene.add(camera);
  79. //光源
  80. var ambientLight = new THREE.AmbientLight('#468be8');
  81. scene.add(ambientLight);
  82. ambientLight.color.setHex(0xffffff);
  83. //背景蓝色
  84. var texture = new THREE.TextureLoader().load('//img12.360buyimg.com/uba/jfs/t1/22824/40/3136/6504/5c24a3f4E76fdafde/802d02d1ec5d3d55.png');
  85. var material = new THREE.MeshBasicMaterial({map:texture,transparent:true,});
  86. var geometry = new THREE.PlaneBufferGeometry(1174,923);
  87. //货物箱
  88. var texture1 = new THREE.TextureLoader().load('//img14.360buyimg.com/uba/jfs/t1/21115/40/3224/5652/5c24a411E03ef9eb6/83781b97e59da905.png');
  89. var material1 = new THREE.MeshBasicMaterial({map:texture1,transparent:true});
  90. var geometry1 = new THREE.PlaneBufferGeometry(146,206);
  91. //人物
  92. var texture2 = new THREE.TextureLoader().load('//img12.360buyimg.com/uba/jfs/t1/9330/16/10894/8662/5c24a42aE708692b3/14455d20eca1ccee.png');
  93. var material2 = new THREE.MeshBasicMaterial({map:texture2,transparent:true});
  94. var geometry2 = new THREE.PlaneBufferGeometry(230,417);
  95. //phone
  96. var texture3 = new THREE.TextureLoader().load('//img10.360buyimg.com/uba/jfs/t1/19171/19/3175/23282/5c24a440Ee2a94261/45321aeaf173f237.png');
  97. var material3 = new THREE.MeshBasicMaterial({map:texture3,transparent:true});
  98. var geometry3 = new THREE.PlaneBufferGeometry(284,524);
  99. //flower
  100. var texture4 = new THREE.TextureLoader().load('//img13.360buyimg.com/uba/jfs/t1/20972/11/3212/7155/5c24a45aE356f126d/2649726673daddc8.png');
  101. var material4 = new THREE.MeshBasicMaterial({map:texture4,transparent:true});
  102. var geometry4 = new THREE.PlaneBufferGeometry(257,193);
  103. //nut
  104. var texture5 = new THREE.TextureLoader().load('//img14.360buyimg.com/uba/jfs/t1/21247/15/3196/859/5c24a472E1e9853ab/6bec8c6940288bc3.png');
  105. var material5 = new THREE.MeshPhongMaterial({
  106. map:texture5,
  107. transparent:true,
  108. opacity:1
  109. });
  110. var geometry5 = new THREE.PlaneBufferGeometry(57,57);
  111. //fly
  112. var texture6 = new THREE.TextureLoader().load('//img14.360buyimg.com/uba/jfs/t1/7300/6/10801/16348/5c24a487E98a8139b/27b70ff5b4ddaf1f.png');
  113. var material6 = new THREE.MeshBasicMaterial({map:texture6,transparent:true,opacity:0});
  114. var geometry6 = new THREE.PlaneBufferGeometry(851,597);
  115. //flyContents
  116. var fly_texture_1_1 = new THREE.TextureLoader().load('//img14.360buyimg.com/uba/jfs/t1/24669/35/3260/1611/5c24a4a9E4e0941ab/65a238650812a7a9.png');
  117. var fly_materila_1_1 = new THREE.MeshBasicMaterial({map:fly_texture_1_1,transparent:true,opacity:0});
  118. fly_materila_1_1.side = THREE.DoubleSide;
  119. var fly_geometry_1_1 = new THREE.PlaneBufferGeometry(77,77);
  120. var fly_texture_1_2 = new THREE.TextureLoader().load('//img10.360buyimg.com/uba/jfs/t1/16477/11/3111/645/5c24a4beE3668b9c1/f7f0b074baab071c.png');
  121. var fly_materila_1_2 = new THREE.MeshBasicMaterial({map:fly_texture_1_2,transparent:true,opacity:0});
  122. fly_materila_1_2.side = THREE.DoubleSide;
  123. var fly_geometry_1_2 = new THREE.PlaneBufferGeometry(54,45);
  124. var fly_texture_2_1 = new THREE.TextureLoader().load('//img12.360buyimg.com/uba/jfs/t1/8267/36/10934/1385/5c24a4d2E036f7ef1/d88f41ccd8d8f409.png');
  125. var fly_materila_2_1 = new THREE.MeshBasicMaterial({map:fly_texture_2_1,transparent:true,opacity:0});
  126. fly_materila_2_1.side = THREE.DoubleSide;
  127. var fly_geometry_2_1 = new THREE.PlaneBufferGeometry(103,74);
  128. var fly_texture_2_2 = new THREE.TextureLoader().load('//img20.360buyimg.com/uba/jfs/t1/9695/33/10662/1607/5c24a4e4Ee2f9bab1/18c829d3e46efc4e.png');
  129. var fly_materila_2_2 = new THREE.MeshBasicMaterial({map:fly_texture_2_2,transparent:true,opacity:0});
  130. fly_materila_2_2.side = THREE.DoubleSide;
  131. var fly_geometry_2_2 = new THREE.PlaneBufferGeometry(69,79);
  132. var fly_texture_3_1 = new THREE.TextureLoader().load('//img12.360buyimg.com/uba/jfs/t1/27128/26/3128/1206/5c24a4faEb2c39e88/825abcfc5fc19761.png');
  133. var fly_materila_3_1 = new THREE.MeshBasicMaterial({map:fly_texture_3_1,transparent:true,opacity:0});
  134. fly_materila_3_1.side = THREE.DoubleSide;
  135. var fly_geometry_3_1 = new THREE.PlaneBufferGeometry(52,53);
  136. var fly_texture_3_2 = new THREE.TextureLoader().load('//img12.360buyimg.com/uba/jfs/t1/29872/1/3250/1154/5c24a50eE15e06d48/2412d3d556bf7463.png');
  137. var fly_materila_3_2 = new THREE.MeshBasicMaterial({map:fly_texture_3_2,transparent:true,opacity:0});
  138. fly_materila_3_2.side = THREE.DoubleSide;
  139. var fly_geometry_3_2 = new THREE.PlaneBufferGeometry(73,73);
  140. var plane = new THREE.Mesh( geometry, material );
  141. plane.position.x = 450;
  142. plane.position.y = 80;
  143. scene.add( plane );
  144. var plane1 = new THREE.Mesh(geometry1,material1);
  145. plane1.position.x = 220;
  146. plane1.position.y = -170;
  147. scene.add(plane1);
  148. var plane3 = new THREE.Mesh(geometry3,material3);
  149. plane3.position.x = 570;
  150. plane3.position.y = -12;
  151. scene.add(plane3);
  152. var plane5 = new THREE.Mesh(geometry5,material5);
  153. plane5.position.x = 505;
  154. plane5.position.y = 147;
  155. scene.add(plane5);
  156. var plane2 = new THREE.Mesh(geometry2,material2);
  157. plane2.position.x = 420;
  158. plane2.position.y = -65;
  159. scene.add(plane2);
  160. var plane4 = new THREE.Mesh(geometry4,material4);
  161. plane4.position.x = 770;
  162. plane4.position.y = -175;
  163. scene.add(plane4);
  164. var plane6 = new THREE.Mesh(geometry6,material6);
  165. plane6.position.x = 498;
  166. plane6.position.y = 23;
  167. scene.add(plane6);
  168. var planeFly_1_1 = new THREE.Mesh(fly_geometry_1_1,fly_materila_1_1);
  169. planeFly_1_1.position.x = 305;
  170. planeFly_1_1.position.y = 220;
  171. scene.add(planeFly_1_1);
  172. var planeFly_1_2 = new THREE.Mesh(fly_geometry_1_2,fly_materila_1_2);
  173. planeFly_1_2.position.x = 385;
  174. planeFly_1_2.position.y = 225;
  175. scene.add(planeFly_1_2);
  176. var planeFly_2_1 = new THREE.Mesh(fly_geometry_2_1,fly_materila_2_1);
  177. planeFly_2_1.position.x = 770;
  178. planeFly_2_1.position.y = 20;
  179. scene.add(planeFly_2_1);
  180. var planeFly_2_2 = new THREE.Mesh(fly_geometry_2_2,fly_materila_2_2);
  181. planeFly_2_2.position.x = 820;
  182. planeFly_2_2.position.y = 90;
  183. scene.add(planeFly_2_2);
  184. var planeFly_3_1 = new THREE.Mesh(fly_geometry_3_1,fly_materila_3_1);
  185. planeFly_3_1.position.x = 500;
  186. planeFly_3_1.position.y = -130;
  187. scene.add(planeFly_3_1);
  188. var planeFly_3_2 = new THREE.Mesh(fly_geometry_3_2,fly_materila_3_2);
  189. planeFly_3_2.position.x = 350;
  190. planeFly_3_2.position.y = -200;
  191. scene.add(planeFly_3_2);
  192. var flyTweenParams ={
  193. x:565,y:147,op:0,r:70,g:139,b:232
  194. }
  195. var flyTween = new TWEEN.Tween(flyTweenParams).easing(TWEEN.Easing.Quadratic.Out).to({x:505,y:147,op:1,r:255,g:255,b:255},3000).onUpdate(function(p){
  196. plane5.position.x = p.x;
  197. plane5.position.y = p.y;
  198. material5.opacity = p.op;
  199. ambientLight.color.setRGB(p.r/255,p.g/255,p.b/255);
  200. }).start();
  201. var flyTweenBack = new TWEEN.Tween(flyTweenParams).easing(TWEEN.Easing.Quadratic.Out).to({x:565,y:147,op:0,r:70,g:139,b:232},3000).onUpdate(function(p){
  202. plane5.position.x = p.x;
  203. plane5.position.y = p.y;
  204. material5.opacity = p.op;
  205. ambientLight.color.setRGB(p.r/255,p.g/255,p.b/255);
  206. });
  207. var flyContentsOp = {
  208. op:0,
  209. };
  210. var flyContentTween = new TWEEN.Tween(flyContentsOp).easing(TWEEN.Easing.Quadratic.Out).to({op:1},2500)
  211. .onUpdate(function(p){
  212. fly_materila_1_1.opacity =
  213. fly_materila_1_2.opacity =
  214. fly_materila_2_1.opacity =
  215. fly_materila_2_2.opacity =
  216. fly_materila_3_1.opacity =
  217. fly_materila_3_2.opacity =
  218. material6.opacity =p.op
  219. })
  220. var flyContentTweenBack = new TWEEN.Tween(flyContentsOp).easing(TWEEN.Easing.Quadratic.Out).to({op:0},2000)
  221. .onUpdate(function(p){
  222. fly_materila_1_1.opacity =
  223. fly_materila_1_2.opacity =
  224. fly_materila_2_1.opacity =
  225. fly_materila_2_2.opacity =
  226. fly_materila_3_1.opacity =
  227. fly_materila_3_2.opacity =
  228. material6.opacity = p.op
  229. })
  230. flyTween.chain(flyContentTween);
  231. //flyContentTween.chain(flyTween);
  232. flyContentTween.chain(flyContentTweenBack);
  233. flyContentTweenBack.chain(flyTweenBack);
  234. flyTweenBack.chain(flyTween);
  235. //flyContentTweenBack.chain(flyContentTween);
  236. //监听事件
  237. document.querySelector('#mouseDiv').addEventListener('mousemove',onDocumentMouseMove,false);
  238. window.addEventListener('resize',onWindowResize,false);
  239. var timer = null;
  240. function onWindowResize(event){
  241. SCREEN_HEIGHT = window.innerHeight;
  242. SCREEN_WIDTH = window.innerWidth;
  243. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  244. camera.updateProjectionMatrix();
  245. renderer.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
  246. }
  247. function onDocumentMouseMove(event){
  248. clearTimeout(timer);
  249. timer = setTimeout(function(){
  250. if(tween){
  251. tween.stop();
  252. }
  253. if(event.clientX - mouseX > 100){
  254. tween = new TWEEN.Tween(planeObj).easing(TWEEN.Easing.Quadratic.Out).to({x:520,y:150},1000).onUpdate(function(p){
  255. plane.position.x = p.x;
  256. plane.position.y = p.y;
  257. }).start();
  258. }else if(event.clientX - mouseX < -100){
  259. tween = new TWEEN.Tween(planeObj).easing(TWEEN.Easing.Quadratic.Out).to({x:450,y:80},1000).onUpdate(function(p){
  260. plane.position.x = p.x;
  261. plane.position.y = p.y;
  262. }).start();
  263. }
  264. tween.start();
  265. mouseX = event.clientX;
  266. mouseY = event.clientY;
  267. },100)
  268. }
  269. function render(){
  270. var timer = Date.now() * 0.0001;
  271. requestAnimationFrame(render);
  272. TWEEN.update();
  273. //渲染,输出
  274. renderer.render(scene, camera);
  275. }
  276. render();
  277. })
  278. }
  279. },
  280. watch:{
  281. },
  282. computed:{
  283. },
  284. created(){
  285. },
  286. mounted(){
  287. this.$nextTick(()=>{
  288. if (!Detector.webgl) {
  289. //Detector.addGetWebGLMessage();
  290. }else{
  291. this.notWebgl = false;
  292. this.threeAnimation();
  293. }
  294. })
  295. },
  296. destroyed(){
  297. }
  298. }
  299. </script>
  300. <style lang="scss" scoped>
  301. .wrapper{
  302. position: fixed;
  303. top:0;
  304. right:0;
  305. bottom:0;
  306. left:0;
  307. .header{
  308. top:0;
  309. min-width:990px;
  310. width:100%;
  311. z-index:999;
  312. height:64px;
  313. }
  314. .meun{
  315. position: absolute;
  316. top:0;
  317. right:14%;
  318. width:376px;
  319. font-size:12px;
  320. li{
  321. float:left;
  322. width:70px;
  323. text-align: center;
  324. height:64px;
  325. line-height: 64px;
  326. cursor: pointer;
  327. color:#fff;
  328. }
  329. select{
  330. width:74px;
  331. height:28px;
  332. margin-top:18px;
  333. margin-left:20px;
  334. font-size:12px;
  335. }
  336. li:hover{
  337. border-bottom:2px solid #fff;
  338. }
  339. .github-icon{
  340. display:inline-block;
  341. height:26px;
  342. width:26px;
  343. font-size:0;
  344. background:url(' ./asset/css/i/github.png') 0 0 no-repeat;
  345. vertical-align: middle;
  346. position: relative;
  347. top:-1px;
  348. margin-left:35px;
  349. cursor: pointer;
  350. }
  351. }
  352. .logo{
  353. height:100%;
  354. line-height:64px;
  355. float: left;
  356. width:245px;
  357. font-size:0;
  358. position: relative;
  359. s{
  360. background:url(./asset/css/i/logo2.png) 0 0 no-repeat;
  361. height:46px;
  362. width:120px;
  363. display: inline-block;
  364. position: absolute;
  365. top:50%;
  366. left:50px;
  367. margin-top:-23px;
  368. }
  369. }
  370. .search{
  371. margin:20px 0;
  372. display: inline-block;
  373. border-left:1px solid #d8d8d8;
  374. padding-left:84px;
  375. position: relative;
  376. &:before{
  377. content:'';
  378. display:inline-block;
  379. background:url(./asset/css/i/search.png) 0 0 no-repeat;
  380. height:22px;
  381. width:22px;
  382. position: absolute;
  383. top:50%;
  384. margin-top:-11px;
  385. left:40px;
  386. }
  387. .search-input{
  388. border:none;
  389. height:24px;
  390. line-height:24px;
  391. font-size:12px;
  392. outline: none;
  393. width:200px;
  394. background:transparent;
  395. }
  396. }
  397. .content{
  398. padding:250px 0 0 8.8%;
  399. z-index: 999;
  400. position: relative;
  401. .mouseDiv{
  402. height:300px;
  403. width:500px;
  404. //background:#ccc;
  405. position: absolute;
  406. top:50%;
  407. left:50%;
  408. margin-left:-250px;
  409. margin-top:-50px;
  410. }
  411. .title{
  412. font-size: 42px;
  413. color:#333;
  414. font-weight: bold;
  415. }
  416. .sub-title{
  417. font-size:24px;
  418. color:#333;
  419. padding-top:30px;
  420. padding-bottom:100px;
  421. }
  422. .btn,.blue-btn{
  423. border:1px solid #5396ff;
  424. color:#5396ff;
  425. width:130px;
  426. height:40px;
  427. line-height:40px;
  428. text-align: center;
  429. display: inline-block;
  430. font-size:14px;
  431. text-decoration: none;
  432. border-radius: 20px;
  433. }
  434. .blue-btn{
  435. color:#fff;
  436. background:#5396ff;
  437. margin-right:40px;
  438. }
  439. }
  440. }
  441. </style>