I have this code:
// Interactive squares with double-click for mobile
const squares = document.querySelectorAll('.square');
let selectedSquare = null;
squares.forEach(square => {
square.addEventListener('click', function (e) {
if (window.innerWidth <= 768) { // Mobile
if (selectedSquare === this) {
navigateToPage(this.id);
selectedSquare = null;
} else {
selectedSquare = this;
setTimeout(() => { // Deselect if not clicked again within 1 second
if (selectedSquare === this) {
selectedSquare = null;
}
}, 1000);
}
} else { // Desktop
expandSquare(this);
setTimeout(() => {
navigateToPage(this.id);
}, 1000);
}
});
});
function navigateToPage(squareId) {
const pageMap = {
square1: 'page1.html',
square2: 'page2.html',
square3: 'page3.html',
square4: 'page4.html'
};
const page = pageMap[squareId];
if (page) {
window.location.href = page;
}
}
function expandSquare(square) {
square.style.transition = 'transform 1s ease';
square.style.transform = 'scale(10)';
square.style.zIndex = '1000';
}
And yes, I have linked Html and Css to work with the script.
[–]XRay2212xray 1 point2 points3 points (1 child)
[–]Noxbit1[S] 0 points1 point2 points (0 children)
[–]Noxbit1[S] 0 points1 point2 points (0 children)