Lo integre con este código pero se rompe en la línea 88:
/**
// Ejecutar al cargar la página
window.addEventListener("DOMContentLoaded", checkDeviceCompatibility);
window.addEventListener("load", function (event) {
const device = getDeviceInfo();
const topContent = document.getElementById('top-content');
let topContentBottomPosition = 0;
updatePosition();
});
window.addEventListener('resize', updatePosition);
/**
- getDeviceInfo function
- Retorna: {
- type: "xsmall"|"small"|"medium"|"large"|"xlarge",
- width: number,
- height: number,
- orientation: "portrait"|"landscape",
- aspectRatio: number
- }
*/
function getDeviceInfo() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspectRatio = width / height;
const orientation = width > height ? "landscape" : "portrait";
// Breakpoints ajustados (W3.CSS + xsmall)
let type;
if (width < 360) {
type = "xsmall";
} else if (width <= 600) {
type = "small";
} else if (width <= 992) {
type = "medium";
} else if (width <= 1200) {
type = "large";
} else {
type = "xlarge";
}
return {
type, // Tamaño del dispositivo
width, // Ancho del viewport (px)
height, // Alto del viewport (px)
orientation, // "portrait" o "landscape"
aspectRatio // Relación ancho/alto (ej: 1.77 para 16:9)
};
}
// Ejemplo de uso:
const device = getDeviceInfo();
console.log(device);
/**
- Verifica si el dispositivo es compatible
*/
function isDeviceSupported() {
return getDeviceInfo() !== "xsmall";
}
/**
-
Muestra error y deshabilita la app en dispositivos no soportados
*/
function checkDeviceCompatibility() {
if (!isDeviceSupported()) {
// 1. Mostrar mensaje de error
document.getElementById("unsupported-device").classList.remove("w3-hide");
// 2. Ocultar el contenido normal de la app
document.getElementById("app-content").classList.add("w3-hide");
// 3. Opcional: Detener scripts adicionales (si es necesario)
throw new Error("Dispositivo no soportado: viewport < 360px");
}
}
/**
-
Realocate middle content
*/
function updatePosition() {
const rect = topContent.getBoundingClientRect();
topContentBottomPosition = rect.bottom; // Posición del borde inferior respecto al viewport
console.log('Posición inferior de top-content:', topContentBottomPosition + 'px');
// 2) Asegurar que middle-content esté inmediatamente después de top-content
const middleContent = document.getElementById('middle-content');
// Si no tiene posición relativa o absoluta, forzamos un layout correcto
if (getComputedStyle(middleContent).position === 'static') {
middleContent.style.position = 'relative';
}