three实现多窗体共享的三维小球旋转动画效果代码
代码语言:html
所属分类:三维
代码描述:three实现多窗体共享的三维小球旋转动画效果代码,打开新的窗体,新增小球会实时显示。
代码标签: three 多窗体 共享 三维 小球 旋转 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.124.js"></script>
<style type="text/css">
*
{
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<script type="module" >
class WindowManager
{
#windows;
#count;
#id;
#winData;
#winShapeChangeCallback;
#winChangeCallback;
constructor ()
{
let that = this;
// event listener for when localStorage is changed from another window
addEventListener("storage", (event) =>
{
if (event.key == "windows")
{
let newWindows = JSON.parse(event.newValue);
let winChange = that.#didWindowsChange(that.#windows, newWindows);
that.#windows = newWindows;
if (winChange)
{
if (that.#winChangeCallback) that.#winChangeCallback();
}
}
});
// event listener for when current window is about to ble closed
window.addEventListener('beforeunload', function (e)
{
let index = that.getWindowIndexFromId(that.#id);
//remove this window from the list and update local storage
that.#windows.splice(index, 1);
that.updateWindowsLocalStorage();
});
}
// check if theres any changes to the window list
#didWindowsChange (pWins, nWins)
{
if (pWins.length != nWins.length)
{
return true;
}
else
{
let c = false;
for (let i = 0; i < pWins.length; i++)
{
if (pWins[i].id != nWins[i].id) c = true;
}
return c;
}
}
// initiate current window (add metadata for custom data to store with each window instance)
init (metaData)
{
this.#windows = JSON.parse(localStorage.getItem("windows")) || [];
this.#count= localStorage.getItem("count") || 0;
this.#count++;
this.#id = this.#count;
let shape = this.getWinShape();
this.#winData = {id: this.#id, shape: shape, metaData: metaData};
this.#windows.push(this.#winData);
localStorage.setItem("count", this.#count);
this.updateWindowsLocalStorage();
}
getWinShape ()
{
let shape = {x: window.screenLeft, y: window.scre.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0