// Funzioni condivise tra le pagine document.addEventListener('DOMContentLoaded', function() { // Inizializza i tooltip const tooltips = document.querySelectorAll('[data-tooltip]'); tooltips.forEach(tooltip => { tooltip.addEventListener('mouseenter', function() { const tooltipText = this.getAttribute('data-tooltip'); const tooltipElement = document.createElement('div'); tooltipElement.className = 'absolute z-50 bg-black text-white text-sm px-3 py-1 rounded-md'; tooltipElement.textContent = tooltipText; this.appendChild(tooltipElement); this.addEventListener('mouseleave', function() { tooltipElement.remove(); }); }); }); // Scorrimento fluido per i link interni document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); // Toggle menu mobile (usato dal componente navbar) window.toggleMobileMenu = function() { const menu = document.getElementById('mobile-menu'); menu.classList.toggle('hidden'); }; }); // Funzione per caricare modelli 3D (usata in più pagine) function load3DModel(containerId, modelConfig) { const container = document.getElementById(containerId); if (!container) return; // Basic Three.js setup const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); renderer.setSize(container.clientWidth, container.clientHeight); container.innerHTML = ''; container.appendChild(renderer.domElement); // Add lights const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); scene.add(ambientLight); const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); directionalLight.position.set(1, 1, 1); scene.add(directionalLight); // Controls const controls = new THREE.OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; // Add model based on config if (modelConfig.type === 'muscle') { // Modello muscolare semplificato const geometry = new THREE.SphereGeometry(1, 32, 32); const material = new THREE.MeshPhongMaterial({ color: 0xff6b6b, transparent: true, opacity: 0.8 }); const sphere = new THREE.Mesh(geometry, material); scene.add(sphere); } else if (modelConfig.type === 'skeleton') { // Modello scheletrico semplificato const geometry = new THREE.BoxGeometry(1, 2, 1); const material = new THREE.MeshPhongMaterial({ color: 0xf5f5f5, wireframe: false }); const bone = new THREE.Mesh(geometry, material); scene.add(bone); } // Posiziona la camera camera.position.z = modelConfig.cameraDistance || 5; // Ciclo di animazione function animate() { requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); } // Gestisce il ridimensionamento della finestra window.addEventListener('resize', function() { camera.aspect = container.clientWidth / container.clientHeight; camera.updateProjectionMatrix(); renderer.setSize(container.clientWidth, container.clientHeight); }); animate(); }