The bottom buttons must not collide with each other when i keep zooming. if there is not enough space and they're about to collide, they must not grow anymyre
<div id="caption" class="caption"></div>
<script>
const questions = [
{ text: "Do you believe there is a higher power or force at work in the conflict between humans and machines?", link: "../questions/morpheus/morpheusdybtiahpoawitcbham.html" },
{ text: "Do you have any doubts about the prophecy or Neo's role as \"The One\"?", link: "../questions/morpheus/morpheusdyhadatorno.html" },
{ text: "Do you know about the Oracle's deal with the Merovingian to save Sati?", link: "../questions/morpheus/morpheusdykatodwts.html" },
{ text: "How did you acquire the Nebuchadnezzar?", link: "../questions/morpheus/morpheushdyatn.html" },
{ text: "How did you escape the Matrix?", link: "../questions/morpheus/morpheushdyetm.html" },
{ text: "What are your long-term goals for humanity?", link: "../questions/morpheus/morpheuswaygfh.html" },
{ text: "What are your thoughts on the Oracle's methods?", link: "../questions/morpheus/morpheuswayotom.html" },
{ text: "What did the Oracle specifically tell you about the previous five \"Ones\"?", link: "../questions/morpheus/morpheuswdtostyatpfo.html" },
{ text: "What is your personal philosophy on the nature of reality?", link: "../questions/morpheus/morpheuswiypotno.html" },
{ text: "What was the turning point for you after the fifth \"One\" died?", link: "../questions/morpheus/morpheuswttfyaftffo.html" }
];
// Sort questions alphabetically
questions.sort((a, b) => a.text.localeCompare(b.text));
function loadButtons() {
const buttonGroup = document.getElementById('button-group');
let delay = 1;
questions.forEach(question => {
const button = document.createElement('button');
button.classList.add('dropdown-button');
button.textContent = question.text;
button.style.setProperty('--delay', delay);
button.onclick = () => {
window.location.href = question.link;
};
buttonGroup.appendChild(button);
delay++;
});
}
window.addEventListener('load', loadButtons);
function loadMedia() {
const imageSpace = document.getElementById('image-space');
const video = document.createElement('video');
video.src = 'C:/Users/PC/Desktop/guest/WEB BUILD/lucidity/images/morpheus2.mp4';
video.autoplay = true;
video.muted = true;
imageSpace.appendChild(video);
video.addEventListener('ended', () => {
video.style.display = 'none';
const img = new Image();
img.src = 'C:/Users/PC/Desktop/guest/WEB BUILD/lucidity/images/morpheus2.png';
img.onload = () => {
imageSpace.appendChild(img);
};
});
}
function scrollUp() {
const buttonGroup = document.querySelector('.left-half .button-group');
const vh = window.innerHeight * 0.01;
buttonGroup.scrollTop -= 5 * vh;
}
function scrollDown() {
const buttonGroup = document.querySelector('.left-half .button-group');
const vh = window.innerHeight * 0.01;
buttonGroup.scrollTop += 5 * vh;
}
const chatButton = document.getElementById('chat-button');
const captionElement = document.getElementById('caption');
chatButton.addEventListener('click', () => {
captionElement.textContent = "This feature is not available yet";
captionElement.classList.add('show');
setTimeout(() => {
captionElement.classList.remove('show');
}, 3000);
});
function adjustLayout() {
const zoomLevel = window.devicePixelRatio;
const newScaleFactor = 1 * zoomLevel;
/* Apply the same scale factor to both main and bottom buttons */
document.documentElement.style.setProperty('--scale-factor', newScaleFactor);
}
function adjustButtonHeights() {
const buttons = document.querySelectorAll('.bottom-button');
let maxHeight = 0;
buttons.forEach(button => {
// Reset height to auto to get the natural height
button.style.height = 'auto';
if (button.offsetHeight > maxHeight) {
maxHeight = button.offsetHeight;
}
});
// Set all buttons to the maximum height
buttons.forEach(button => {
button.style.height = `${maxHeight}px`;
});
}
// Debounce function to optimize resize events
function debounce(func, wait) {
let timeout;
return function (...args) {
const later = () => {
clearTimeout(timeout);
func.apply(this, args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
window.addEventListener('resize', debounce(() => {
adjustLayout();
adjustButtonHeights();
}, 150));
// Initial adjustments on load
window.addEventListener('load', () => {
adjustLayout();
adjustButtonHeights();
});
</script>
To ensure that the bottom buttons do not collide when the user zooms in, you need to implement constraints that prevent the buttons from growing beyond the available space. This can be achieved by:
Setting Maximum Sizes: Define max-width and max-height for the buttons to prevent them from expanding indefinitely.
Adjusting the Scaling Mechanism: Limit the --scale-factor to a maximum value in your JavaScript.
Using Flexbox Properties Effectively: Ensure that the flex container handles the layout gracefully without causing overlaps.
Below are the detailed steps and code modifications to achieve this:
1. Limit the Scale Factor in JavaScript
First, modify your JavaScript to restrict the --scale-factor to a maximum value. This prevents the buttons from scaling beyond a certain point, ensuring they do not collide.
javascript
function adjustLayout() {
const zoomLevel = window.devicePixelRatio;
// Set a maximum scale factor, e.g., 2
const maxScaleFactor = 2;
const newScaleFactor = Math.min(1 * zoomLevel, maxScaleFactor);
/* Apply the same scale factor to both main and bottom buttons */
document.documentElement.style.setProperty('--scale-factor', newScaleFactor);
}
2. Define Maximum Sizes in CSS
Next, set max-width and max-height for the .bottom-button class to ensure that buttons do not exceed these dimensions, regardless of the scale factor.
Adjust the max-width and max-height values (10vh and 5vh in this example) according to your design requirements.
3. Ensure Flex Container Manages Layout Properly
Make sure the flex container .bottom-buttons-container handles the layout without causing overlaps. You can adjust flex-wrap and alignment properties as needed.
css
.bottom-buttons-container {
display: flex;
justify-content: space-between;
align-items: center; /* Vertically centers the buttons */
padding-top: 0.9vh; /* Changed from 9px to 0.9vh for responsiveness */
padding-bottom: 0.9vh; /* Changed from 9px to 0.9vh */
margin-bottom: -0.9vh; /* Adjusted to counteract padding and maintain position */
width: 100%;
gap: 1vh; /* Ensures consistent spacing between button groups */
box-sizing: border-box; /* Includes padding in layout calculations */
flex-wrap: wrap; /* Allows buttons to wrap to the next line if necessary */
}
4. Optional: Use Media Queries for Better Responsiveness
You can also use CSS media queries to adjust the layout or button sizes based on the viewport size to enhance responsiveness further.
Added max-width and max-height to .bottom-button to cap the size of the buttons.
Enabled flex-wrap: wrap on .bottom-buttons-container to allow buttons to move to the next line if necessary.
css
.bottom-button {
/* Existing styles */
max-width: 10vh; /* Prevent buttons from growing too large */
max-height: 5vh; /* Prevent buttons from growing too large */
}
.bottom-buttons-container {
/* Existing styles */
flex-wrap: wrap; /* Allows buttons to wrap to the next line if necessary */
}
Responsive Adjustments:
Used media queries to further adjust button sizes on smaller screens, enhancing responsiveness.
By implementing these changes, the bottom buttons will maintain their size within the available space, preventing collisions when the user zooms in. The buttons will stop growing once they reach the defined maximum sizes, ensuring a consistent and collision-free layout.
Feel free to adjust the max-width and max-height values to better suit your design needs. Additionally, testing across different devices and screen sizes will help ensure the layout remains robust and user-friendly.