是的我又來了,畢竟,今天七夕:: 願天下有情人成眷屬html
不肯勾起相思,不敢出門看月。恰恰月進窗來,害我相思一晚上。我關掉月亮,你甚至更明朗。
上地址:jquery
演示地址:http://alterem.gitee.io/ddvs/git
代碼比較簡單,紅本是之前的元素週期表。。app
<body> <script src="js/jquery.min.js"></script> <script src="js/three.js"></script> <script src="js/tween.min.js"></script> <script src="js/TrackballControls.js"></script> <script src="js/CSS3DRenderer.js"></script> <div id="container"></div> <audio autoplay="" loop=""><source src="http://www.ytmp3.cn/down/72794.mp3"></audio> <div id="info">照片牆</div> <div id="menu"> <button id="table">表格</button> <button id="sphere">球球</button> <button id="helix">螺旋</button> <button id="grid">格子</button> </div> <div class="show_info animated" style="display:none;"> <div class="info_my"> <img src="img/c.png" /> <div class="info_mem"> <div class="nickname">趙璐思</div> <div class="id">ID:女友</div> <div class="vote">性別:女</div> </div> </div> <div class="intro">若是能夠交換人生,就跟之前的本身交換吧, 能夠少些遺憾,並且,該在的人都在。</div> </div> <script> var personArray = new Array; var CurPersonNum = 0; // animate var _in = ['bounceIn','bounceInDown','bounceInLeft','bounceInRight','bounceInUp','fadeIn','fadeInDown','fadeInDownBig','fadeInLeft','fadeInLeftBig','fadeInRight','fadeInRightBig','fadeInUp','fadeInUpBig','rotateIn','rotateInDownLeft','rotateInDownRight','rotateInUpLeft','rotateInUpRight','slideInDown','slideInLeft','slideInRight']; var _out = ['bounceOut','bounceOutDown','bounceOutLeft','bounceOutRight','bounceOutUp','fadeOut','fadeOutDown','fadeOutDownBig','fadeOutLeft','fadeOutLeftBig','fadeOutRight','fadeOutRightBig','fadeOutUp','fadeOutUpBig','rotateOut','rotateOutDownLeft','rotateOutDownRight','rotateOutUpLeft','rotateOutUpRight','slideOutDown','slideOutLeft','slideOutRight']; // 模擬推送數據 var s = setInterval(function(){ // get animate var rand_in = parseInt(Math.random() * _in.length,10); var rand_out = parseInt(Math.random() * _out.length,10); if(CurPersonNum >= personArray.length){ CurPersonNum = 0; } },4500); // 生成虛擬數據 for(var i=0;i<199;i++){ personArray.push({ image: "img/a.png" }, { image: "img/b.png" }, { image: "img/c.png" }); } var table = new Array; for (var i = 0; i < personArray.length; i++) { table[i] = new Object(); if (i < personArray.length) { table[i] = personArray[i]; table[i].src = personArray[i].thumb_image; } table[i].p_x = i % 20 + 1; table[i].p_y = Math.floor(i / 20) + 1; } var camera, scene, renderer; var controls; var objects = []; var targets = { table: [], sphere: [], helix: [], grid: [] }; init(); animate(); function init() { camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 ); camera.position.z = 3000; scene = new THREE.Scene(); // table for ( var i = 0; i < table.length; i ++ ) { var element = document.createElement( 'div' ); element.className = 'element'; element.style.backgroundColor = 'rgba(0,127,127,' + ( Math.random() * 0.5 + 0.25 ) + ')'; var img = document.createElement('img'); img.src = table[ i ].image; element.appendChild( img ); /*var number = document.createElement( 'div' ); number.className = 'number'; number.textContent = (i/5) + 1; element.appendChild( number ); var symbol = document.createElement( 'div' ); symbol.className = 'symbol'; symbol.textContent = table[ i ]; element.appendChild( symbol ); var details = document.createElement( 'div' ); details.className = 'details'; details.innerHTML = table[ i + 1 ] + '<br>' + table[ i + 2 ]; element.appendChild( details );*/ var object = new THREE.CSS3DObject( element ); object.position.x = Math.random() * 4000 - 2000; object.position.y = Math.random() * 4000 - 2000; object.position.z = Math.random() * 4000 - 2000; scene.add( object ); objects.push( object ); // 表格須要座標進行排序的 var object = new THREE.Object3D(); // object.position.x = ( table[ i + 3 ] * 140 ) - 1330; // object.position.y = - ( table[ i + 4 ] * 180 ) + 990; object.position.x = ( table[ i ].p_x * 140 ) - 1330; object.position.y = - ( table[ i ].p_y * 180 ) + 990; targets.table.push( object ); } // sphere var vector = new THREE.Vector3(); var spherical = new THREE.Spherical(); for ( var i = 0, l = objects.length; i < l; i ++ ) { var phi = Math.acos( -1 + ( 2 * i ) / l ); var theta = Math.sqrt( l * Math.PI ) * phi; var object = new THREE.Object3D(); spherical.set( 800, phi, theta ); object.position.setFromSpherical( spherical ); vector.copy( object.position ).multiplyScalar( 2 ); object.lookAt( vector ); targets.sphere.push( object ); } // helix var vector = new THREE.Vector3(); var cylindrical = new THREE.Cylindrical(); for ( var i = 0, l = objects.length; i < l; i ++ ) { var theta = i * 0.175 + Math.PI; var y = - ( i * 5 ) + 450; var object = new THREE.Object3D(); // 參數一 圈的大小 參數二 左右間距 參數三 上下間距 cylindrical.set( 900, theta, y ); object.position.setFromCylindrical( cylindrical ); vector.x = object.position.x * 2; vector.y = object.position.y; vector.z = object.position.z * 2; object.lookAt( vector ); targets.helix.push( object ); } // grid for ( var i = 0; i < objects.length; i ++ ) { var object = new THREE.Object3D(); object.position.x = ( ( i % 5 ) * 400 ) - 800; // 400 圖片的左右間距 800 x軸中心店 object.position.y = ( - ( Math.floor( i / 5 ) % 5 ) * 300 ) + 500; // 500 y軸中心店 object.position.z = ( Math.floor( i / 25 ) ) * 200 - 800;// 300調整 片間距 800z軸中心店 targets.grid.push( object ); } //渲染 renderer = new THREE.CSS3DRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); renderer.domElement.style.position = 'absolute'; document.getElementById( 'container' ).appendChild( renderer.domElement ); // 鼠標控制 controls = new THREE.TrackballControls( camera, renderer.domElement ); controls.rotateSpeed = 0.5; controls.minDistance = 500; controls.maxDistance = 6000; controls.addEventListener( 'change', render ); // 自動更換 var ini = 0; setInterval(function(){ ini = ini >= 3 ? 0 : ini; ++ini; switch(ini){ case 1: transform( targets.sphere, 1000 ); break; case 2: transform( targets.helix, 1000 ); break; case 3: transform( targets.grid, 1000 ); break; } },8000); var button = document.getElementById( 'table' ); button.addEventListener( 'click', function ( event ) { transform( targets.table, 1000 ); }, false ); var button = document.getElementById( 'sphere' ); button.addEventListener( 'click', function ( event ) { transform( targets.sphere, 2000 ); }, false ); var button = document.getElementById( 'helix' ); button.addEventListener( 'click', function ( event ) { transform( targets.helix, 2000 ); }, false ); var button = document.getElementById( 'grid' ); button.addEventListener( 'click', function ( event ) { transform( targets.grid, 2000 ); }, false ); transform( targets.table, 2000 ); // window.addEventListener( 'resize', onWindowResize, false ); } function transform( targets, duration ) { TWEEN.removeAll(); for ( var i = 0; i < objects.length; i ++ ) { var object = objects[ i ]; var target = targets[ i ]; new TWEEN.Tween( object.position ) .to( { x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration ) .easing( TWEEN.Easing.Exponential.InOut ) .start(); new TWEEN.Tween( object.rotation ) .to( { x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration ) .easing( TWEEN.Easing.Exponential.InOut ) .start(); } new TWEEN.Tween( this ) .to( {}, duration * 2 ) .onUpdate( render ) .start(); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); render(); } function animate() { // 讓場景經過x軸或者y軸旋轉 & z // scene.rotation.x += 0.011; scene.rotation.y += 0.008; requestAnimationFrame( animate ); TWEEN.update(); controls.update(); // 渲染循環 render(); } function render() { renderer.render( scene, camera ); } </script> </body>
最後源碼地址:dom