基于Three.js實(shí)現(xiàn)360度全景圖片
Three.js 是一款運(yùn)行在瀏覽器中的3D引擎, 處理三維效果。在一些相機(jī)的官網(wǎng)首頁中,經(jīng)常有一張圖在旋轉(zhuǎn),圖上面懸浮著文字。這種效果是如何做出來的呢?先看效果,再講解。

1).建立一個(gè)java web 工程(或者其他工程), 因?yàn)閠hree.js 的全景圖要通過服務(wù)端瀏覽(安全的考慮)

2).在上面的結(jié)構(gòu)中,只有css中的index.css是自定義的,其余css和js都屬于three.js自帶的工具文件。包含圖片在內(nèi),已經(jīng)上傳資源了,點(diǎn)擊此處下載。
3).index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基于Three.js的360度全景圖片</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/default.css" >
<link rel="stylesheet" type="text/css" href="css/index.css" >
<script src="js/three.min.js"></script>
<script src="js/photo-sphere-viewer.min.js"></script>
</head>
<body>
<div class="container">
<div class="description">
<h1>苑中遇雪</h1>
<p> 紫禁仙輿詰旦來,青旂遙倚望春臺。</p>
<p>不知庭霰今朝落,疑是林花昨夜開。</p>
</div>
<div id="my-pano" class="pano"></div>
</div>
</body>
<script>
window.onload = function() {
var div = document.getElementById('my-pano');
var PSV = new PhotoSphereViewer({
// Panorama, given in base 64
panorama: 'images/snow.jpg',
// Container
container: div,
autoload:true,
// Deactivate the animation
time_anim: 2000,
// Display the navigation bar
navbar: true,
// Resize the panorama
size: {
width: '70%',
height: 700
}
});
};
</script>
</html>
4).index.css
body{ text-align:center}
.container {
margin:0 auto;
}
.pano {
margin:0 auto;
z-index:1;
}
.description {
width:400px;
left:350px;
margin-top:40px;
z-index:100;
position:absolute;
float:left;
}
.description h1 {
font-size:40px;
color:#FFF
}
.description p {
font-size:22px;
color:#FFF
}
5).根據(jù)實(shí)際應(yīng)用在瀏覽器測試,全景圖可自動(dòng)旋轉(zhuǎn)、可鼠標(biāo)拖拽轉(zhuǎn)動(dòng)、可全屏
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
uniapp實(shí)現(xiàn)單選組件覆蓋選中樣式的方法
最近使用uniapp開發(fā),有些組件渲染之后會生成一些標(biāo)簽,需要修改生成標(biāo)簽的樣式,下面通過實(shí)例代碼講解uniapp實(shí)現(xiàn)單選組件覆蓋選中樣式的方法,感興趣的朋友一起看看吧2024-03-03
JavaScript實(shí)現(xiàn)簡單抽獎(jiǎng)系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡單抽獎(jiǎng)系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
詳解javascript立即執(zhí)行函數(shù)表達(dá)式IIFE
本文主要介紹了javascript立即執(zhí)行函數(shù)表達(dá)式IIFE的相關(guān)知識。具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-02-02
快速解決js動(dòng)態(tài)改變dom元素屬性后頁面及時(shí)渲染的問題
下面小編就為大家?guī)硪黄焖俳鉀Qjs動(dòng)態(tài)改變dom元素屬性后頁面及時(shí)渲染的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07

