Cách Chèn Video 360 Vào Web Wordpress - Code & Coffe
Có thể bạn quan tâm
Nhúng các code iframe sau vào web nhé!
<div class="photo360-desktop"> <iframe style="width: 100%;height: 500px;border: 0px" src="https://iconcentral.vn/360view.php"></iframe> </div>| 123 | <div class="photo360-desktop"><iframe style="width: 100%;height: 500px;border: 0px"src="https://iconcentral.vn/360view.php"></iframe></div> |
| 12 | <iframe src="https://storage.googleapis.com/vrview/2.0/index.html?preview=https://storage.googleapis.com/vrview/examples/coral-preview.jpg&image=https://storage.googleapis.com/vrview/examples/coral.jpg&is_stereo=true&"><span data-mce-type="bookmark"style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;"class="mce_SELRES_start"></span></iframe> |
Đối với hình ảnh 360 độ thì bạn chỉ cần có thiết bị hỗ trợ chụp chế độ panorama là được. Trong bài hướng dẫn này mình sẽ dùng kèm với thư viện three.js.
- Cách đăng hình 360 độ lên WordPress
Cách đăng hình 360 độ lên WordPress
Bạn chỉ có thể dùng iframe để chèn hình ảnh 360 độ vào bài viết. Do vậy, công việc của bạn là tạo ra một tập tin PHP có thể hiển thị ảnh 360.
<?php $src = isset( $_GET['src'] ) ? $_GET['src'] : ''; if ( empty( $src ) ) { return; } $title = isset( $_GET['title'] ) ? $_GET['title'] : 'Hình ảnh 360'; $type = isset( $_GET['type'] ) ? $_GET['type'] : 'equirectangular'; $type = strtolower( $type ); ?> <!DOCTYPE html> <html lang="vi"> <head> <title><?php echo $title; ?></title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <style> body { background-color: #000000; margin: 0; overflow: hidden; } canvas, img { cursor: hand; } canvas, img { cursor: -webkit-grab; } </style> </head> <body> <div id="container"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/90/three.min.js"></script> <script async> var camera, scene, renderer; var isUserInteracting = false, onMouseDownMouseX = 0, onMouseDownMouseY = 0, lon = 0, onMouseDownLon = 0, lat = 0, onMouseDownLat = 0, phi = 0, theta = 0; init(); animate(); function init() { var container, mesh; container = document.getElementById('container'); camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100); camera.target = new THREE.Vector3(0, 0, 0); scene = new THREE.Scene(); var geometry = new THREE.SphereBufferGeometry(500, 60, 40); geometry.scale(-1, 1, 1); var material = new THREE.MeshBasicMaterial({ map: new THREE.TextureLoader().load('<?php echo $src; ?>') }); mesh = new THREE.Mesh(geometry, material); scene.add(mesh); renderer = new THREE.WebGLRenderer(); renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(window.innerWidth, window.innerHeight); container.appendChild(renderer.domElement); document.addEventListener('mousedown', onDocumentMouseDown, false); document.addEventListener('mousemove', onDocumentMouseMove, false); document.addEventListener('mouseup', onDocumentMouseUp, false); document.addEventListener('wheel', onDocumentMouseWheel, false); document.addEventListener('dragover', function (event) { event.preventDefault(); event.dataTransfer.dropEffect = 'copy'; }, false); document.addEventListener('dragenter', function (event) { document.body.style.opacity = 0.5; }, false); document.addEventListener('dragleave', function (event) { document.body.style.opacity = 1; }, false); document.addEventListener('drop', function (event) { event.preventDefault(); var reader = new FileReader(); reader.addEventListener('load', function (event) { material.map.image.src = event.target.result; material.map.needsUpdate = true; }, false); reader.readAsDataURL(event.dataTransfer.files[0]); document.body.style.opacity = 1; }, false); window.addEventListener('resize', onWindowResize, false); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); } function onDocumentMouseDown(event) { event.preventDefault(); isUserInteracting = true; onMouseDownMouseX = event.clientX; onMouseDownMouseY = event.clientY; onMouseDownLon = lon; onMouseDownLat = lat; } function onDocumentMouseMove(event) { if (isUserInteracting === true) { lon = ( onMouseDownMouseX - event.clientX ) * 0.1 + onMouseDownLon; lat = ( event.clientY - onMouseDownMouseY ) * 0.1 + onMouseDownLat; } } function onDocumentMouseUp(event) { isUserInteracting = false; } function onDocumentMouseWheel(event) { var fov = camera.fov + event.deltaY * 0.05; camera.fov = THREE.Math.clamp(fov, 10, 75); camera.updateProjectionMatrix(); } function animate() { requestAnimationFrame(animate); update(); } function update() { if (isUserInteracting === false) { //lon += 0.1; } lat = Math.max(-85, Math.min(85, lat)); phi = THREE.Math.degToRad(90 - lat); theta = THREE.Math.degToRad(lon); camera.target.x = 500 * Math.sin(phi) * Math.cos(theta); camera.target.y = 500 * Math.cos(phi); camera.target.z = 500 * Math.sin(phi) * Math.sin(theta); camera.lookAt(camera.target); renderer.render(scene, camera); } </script> </body> </html>| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 | <?php$src=isset($_GET['src'])?$_GET['src']:''; if(empty($src)){return;} $title=isset($_GET['title'])?$_GET['title']:'Hình ảnh 360';$type=isset($_GET['type'])?$_GET['type']:'equirectangular';$type=strtolower($type);?><!DOCTYPE html><html lang="vi"><head><title><?phpecho$title;?></title><meta charset="utf-8"><meta name="viewport"content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"><style>body {background-color:#000000;margin:0;overflow:hidden;} canvas, img {cursor:hand;} canvas, img {cursor:-webkit-grab;}</style></head><body><div id="container"></div><script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/90/three.min.js"></script><script async>varcamera,scene,renderer; varisUserInteracting=false,onMouseDownMouseX=0,onMouseDownMouseY=0,lon=0,onMouseDownLon=0,lat=0,onMouseDownLat=0,phi=0,theta=0; init();animate(); functioninit(){ varcontainer,mesh; container=document.getElementById('container'); camera=newTHREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,1,1100);camera.target=newTHREE.Vector3(0,0,0); scene=newTHREE.Scene(); vargeometry=newTHREE.SphereBufferGeometry(500,60,40); geometry.scale(-1,1,1); varmaterial=newTHREE.MeshBasicMaterial({map:newTHREE.TextureLoader().load('<?php echo $src; ?>')}); mesh=newTHREE.Mesh(geometry,material); scene.add(mesh); renderer=newTHREE.WebGLRenderer();renderer.setPixelRatio(window.devicePixelRatio);renderer.setSize(window.innerWidth,window.innerHeight);container.appendChild(renderer.domElement); document.addEventListener('mousedown',onDocumentMouseDown,false);document.addEventListener('mousemove',onDocumentMouseMove,false);document.addEventListener('mouseup',onDocumentMouseUp,false);document.addEventListener('wheel',onDocumentMouseWheel,false); document.addEventListener('dragover',function(event){ event.preventDefault();event.dataTransfer.dropEffect='copy'; },false); document.addEventListener('dragenter',function(event){ document.body.style.opacity=0.5; },false); document.addEventListener('dragleave',function(event){ document.body.style.opacity=1; },false); document.addEventListener('drop',function(event){ event.preventDefault(); varreader=newFileReader();reader.addEventListener('load',function(event){ material.map.image.src=event.target.result;material.map.needsUpdate=true; },false);reader.readAsDataURL(event.dataTransfer.files[0]); document.body.style.opacity=1; },false); window.addEventListener('resize',onWindowResize,false); } functiononWindowResize(){ camera.aspect=window.innerWidth/window.innerHeight;camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth,window.innerHeight); } functiononDocumentMouseDown(event){ event.preventDefault(); isUserInteracting=true; onMouseDownMouseX=event.clientX;onMouseDownMouseY=event.clientY; onMouseDownLon=lon;onMouseDownLat=lat; } functiononDocumentMouseMove(event){ if(isUserInteracting===true){ lon=(onMouseDownMouseX-event.clientX)*0.1+onMouseDownLon;lat=(event.clientY-onMouseDownMouseY)*0.1+onMouseDownLat; } } functiononDocumentMouseUp(event){ isUserInteracting=false; } functiononDocumentMouseWheel(event){ varfov=camera.fov+event.deltaY*0.05; camera.fov=THREE.Math.clamp(fov,10,75); camera.updateProjectionMatrix(); } functionanimate(){ requestAnimationFrame(animate);update(); } functionupdate(){ if(isUserInteracting===false){ //lon += 0.1; } lat=Math.max(-85,Math.min(85,lat));phi=THREE.Math.degToRad(90-lat);theta=THREE.Math.degToRad(lon); camera.target.x=500*Math.sin(phi)*Math.cos(theta);camera.target.y=500*Math.cos(phi);camera.target.z=500*Math.sin(phi)*Math.sin(theta); camera.lookAt(camera.target); renderer.render(scene,camera); } </script></body></html> |
Chèn vào web thì như 2 ví dụ bên trên
<iframe src="https://domain.com/360.php?src=http://urlhinhanh.jpg&title=Test+360"></iframe>| 1 | <iframe src="http://domain.com/360.php?src=http://urlhinhanh.jpg&title=Test+360"></iframe> |
Bài viết chưa tốt do mình copy vội! code hoạt động 100% mình sẽ trau chuốt thêm sau, cảm ơn các bạn đã đọc và chúc các bạn thành công!
1/5 - (1 bình chọn) Share Tweet Save Share ShareTừ khóa » Chèn ảnh 360 Vào Web
-
Hướng Dẫn Nhúng ảnh 360 độ Lên Website
-
Cách Tạo ảnh 360 độ Và Chèn Vào Mô Tả Sản Phẩm Trên Website
-
Cách đăng ảnh 360 độ Lên Một Số Website Có Hỗ Trợ
-
Hướng Dẫn Cách Nhúng ảnh 360 độ Vào Website - Hàng Hiệu Giá Tốt
-
Cách Tạo ảnh 360 độ để Chèn Vào Mô Tả Sản ... - Dotnet Tip Of The Day
-
Cách Nhúng ảnh 360 độ Lên Website đơn Giản Từ Momento360
-
Cách đăng ảnh 360 độ Lên Facebook, HoloBuilder Và Một Số ...
-
Cách Chèn Ảnh 360 Vào Bài Viết Website
-
Gắn Link 360 độ Vào Trang Landing Page Bất động Sản
-
Thêm ảnh ° To 360 ° Vào Không Gian SharePoint - Microsoft Support
-
CÁCH CHÈN ẢNH 360 ĐỘ VÀO BLOGSPOT - YouTube
-
Cách Tạo ảnh 360 độ để Chèn Vào Mô Tả Sản Phẩm Trên Trang Web
-
Cách Làm Ảnh 360 Độ - Ruby