forked from EXT/VR180-Web-Player
Fix 2D control panel positioning relative to canvas
- Fix panel positioning calculation to account for panel height - Position panel bottom edge 10% from canvas bottom (not container) - Ensure panel stays within canvas bounds when WebGL canvas is active - Update positioning on window resize for responsive behavior - Resolves issue where panel appeared partially below canvas
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
<source src="sbs-video.mp4" type="video/mp4">
|
<source src="sbs-video.mp4" type="video/mp4">
|
||||||
</video>
|
</video>
|
||||||
<button id="playBtn" aria-label="Play video">
|
<button id="playBtn" aria-label="Play video">
|
||||||
<img src="play.svg" alt="Play">
|
<img src="play.png" alt="Play">
|
||||||
</button>
|
</button>
|
||||||
<div id="panel">
|
<div id="panel">
|
||||||
<div id="status">
|
<div id="status">
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
bottom: 10%;
|
bottom: 10%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
max-width: 1000px;
|
width: 80%;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 30px;
|
border-radius: 30px;
|
||||||
background: rgba(0, 0, 0, 0.70);
|
background: rgba(0, 0, 0, 0.70);
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
z-index: 100;
|
z-index: 100;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
transition: opacity 0.3s ease, visibility 0.3s ease;
|
transition: opacity 0.15s ease, visibility 0.15s ease;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,11 +77,6 @@
|
|||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#panel img {
|
|
||||||
width: 100%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
#status {
|
#status {
|
||||||
margin: 0 12px 12px 12px;
|
margin: 0 12px 12px 12px;
|
||||||
}
|
}
|
||||||
@@ -132,14 +127,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#panel button {
|
#panel button {
|
||||||
all: unset;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: 4px;
|
border: none;
|
||||||
transition: opacity 0.15s ease-in-out;
|
background-color: transparent;
|
||||||
}
|
|
||||||
|
|
||||||
#panel button:hover {
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#fullscreen {
|
#fullscreen {
|
||||||
@@ -217,11 +207,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#play2.playing {
|
#play2.playing {
|
||||||
background-image: url(pause2.png);
|
background-image: url(pause.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
#play2.playing:hover {
|
#play2.playing:hover {
|
||||||
background-image: url(pause2-hover.png);
|
background-image: url(pause-hover.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
#forward {
|
#forward {
|
||||||
@@ -237,28 +227,3 @@
|
|||||||
#forward:hover {
|
#forward:hover {
|
||||||
background-image: url(forward-hover.png);
|
background-image: url(forward-hover.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Responsive adjustments for 2D controls */
|
|
||||||
@media (max-width: 600px) {
|
|
||||||
#panel {
|
|
||||||
max-width: 90%;
|
|
||||||
padding: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#controls {
|
|
||||||
grid-template-columns: 36px 1fr 132px 1fr 36px;
|
|
||||||
height: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#fullscreen, #mute, #back, #play2, #forward {
|
|
||||||
width: 36px;
|
|
||||||
height: 36px;
|
|
||||||
background-size: 36px 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#nav {
|
|
||||||
grid-template-columns: 36px 36px 36px;
|
|
||||||
grid-gap: 8px;
|
|
||||||
height: 36px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -737,6 +737,9 @@ function onWindowResize() {
|
|||||||
renderer.setSize(videoWidth, videoHeight);
|
renderer.setSize(videoWidth, videoHeight);
|
||||||
camera2D.aspect = videoWidth / videoHeight;
|
camera2D.aspect = videoWidth / videoHeight;
|
||||||
camera2D.updateProjectionMatrix();
|
camera2D.updateProjectionMatrix();
|
||||||
|
|
||||||
|
// Reposition control panel after resize
|
||||||
|
position2DControlPanel();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Normal VR/window mode
|
// Normal VR/window mode
|
||||||
@@ -1031,6 +1034,32 @@ function toggle2DFullscreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function position2DControlPanel() {
|
||||||
|
if (!is2DMode || !controlPanel || !renderer) return;
|
||||||
|
|
||||||
|
// Get the canvas dimensions and position
|
||||||
|
const canvas = renderer.domElement;
|
||||||
|
const canvasRect = canvas.getBoundingClientRect();
|
||||||
|
const containerRect = document.getElementById('vr-container').getBoundingClientRect();
|
||||||
|
|
||||||
|
// Calculate 10% from the bottom of the canvas
|
||||||
|
const bottomOffset = canvasRect.height * 0.1;
|
||||||
|
|
||||||
|
// Get the panel's height
|
||||||
|
const panelHeight = controlPanel.offsetHeight;
|
||||||
|
|
||||||
|
// Calculate the top position: canvas bottom minus offset minus panel height, relative to container
|
||||||
|
const topPosition = (canvasRect.bottom - containerRect.top) - bottomOffset - panelHeight;
|
||||||
|
|
||||||
|
// Position the panel so its bottom edge is 10% from canvas bottom
|
||||||
|
controlPanel.style.position = 'absolute';
|
||||||
|
controlPanel.style.top = `${topPosition}px`;
|
||||||
|
controlPanel.style.bottom = 'auto'; // Clear any previous bottom positioning
|
||||||
|
controlPanel.style.left = '50%';
|
||||||
|
controlPanel.style.transform = 'translateX(-50%)';
|
||||||
|
controlPanel.style.zIndex = '1000'; // Ensure it's above the canvas
|
||||||
|
}
|
||||||
|
|
||||||
function formatTime(seconds) {
|
function formatTime(seconds) {
|
||||||
if (!isFinite(seconds)) return '00:00:00';
|
if (!isFinite(seconds)) return '00:00:00';
|
||||||
|
|
||||||
@@ -1256,6 +1285,9 @@ function start2DMode() {
|
|||||||
// Show 2D control panel
|
// Show 2D control panel
|
||||||
show2DControlPanel();
|
show2DControlPanel();
|
||||||
|
|
||||||
|
// Position control panel relative to canvas
|
||||||
|
position2DControlPanel();
|
||||||
|
|
||||||
// Start 2D render loop
|
// Start 2D render loop
|
||||||
render2D();
|
render2D();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user