本篇文章給大家?guī)砹岁P(guān)于前端的相關(guān)知識,其中主要跟大家介紹怎么在前端實現(xiàn)360度全景效果,感興趣的朋友下面一起來看一下吧,希望對大家有幫助。
(相關(guān)資料圖)
效果展示:
使用插件:photo-sphere-viewer
實現(xiàn)代碼:
<!DOCTYPE html><head> <!-- for optimal display on high DPI devices --> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/npm/three/build/three.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@photo-sphere-viewer/core/index.min.js"></script></head><body> <!-- the viewer container must have a defined size --> <div id="viewer" style="width: 100vw; height: 100vh;"></div> <script> const viewer = new PhotoSphereViewer.Viewer({ container: document.querySelector("#viewer"), panorama: "./img/44.jpg", }); </script></body></html>文件目錄:
注意事項:
全景圖路徑如下:
panorama: "./img/44.jpg",
直接本地運行,也就是在瀏覽器中 file:// 開頭,上面的路徑是行不通的。存在跨域問題。
解決圖片加載不出的問題:
啟動服務(wù)器,運行文件。
方法一:
通過 http-server 來實現(xiàn),具體操作如下:
終端執(zhí)行命令:npm install http-server -g全局安裝 http-server
執(zhí)行命令:http-server啟動服務(wù),啟動后如下,會有可訪問鏈接
cmd + 點擊,跳轉(zhuǎn)瀏覽器如下頁面,就可以訪問相應(yīng)的 html 頁面了。(這樣訪問,就可以加載出本地的圖片資源了)
方法二:
通過 vscode 的 live server 擴展運行文件
安裝擴展
相應(yīng)文件右鍵,選擇 open with live server,即可跳轉(zhuǎn)到
以上就是聊聊前端怎么實現(xiàn)360度全景效果的詳細(xì)內(nèi)容,更多請關(guān)注php中文網(wǎng)其它相關(guān)文章!
關(guān)鍵詞: