File size: 10,306 Bytes
a67caf7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
document.addEventListener('DOMContentLoaded', function() {
// Load crystal details if on details page
if (window.location.pathname.includes('details.html')) {
loadCrystalDetails();
}
// Calculator functionality
const radioButtons = document.querySelectorAll('input[name="crystal-structure"]');
const resultsContainer = document.getElementById('calculator-results');
radioButtons.forEach(radio => {
radio.addEventListener('change', function() {
if (this.checked) {
updateCalculator(this.value);
}
function loadCrystalDetails() {
const params = new URLSearchParams(window.location.search);
const structure = params.get('structure');
const detailsContainer = document.getElementById('crystal-details');
if (!structure) {
detailsContainer.innerHTML = `
<div class="text-center py-8">
<i data-feather="alert-triangle" class="w-12 h-12 text-yellow-500 mx-auto mb-4"></i>
<h2 class="text-2xl font-bold text-indigo-800 mb-2">Structure non spécifiée</h2>
<p class="text-gray-600 mb-4">Aucune structure cristalline n'a été spécifiée.</p>
<a href="index.html" class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-md inline-flex items-center">
<i data-feather="home" class="mr-2"></i>
Retour à l'accueil
</a>
</div>
`;
feather.replace();
return;
}
// Simulate loading while we fetch data
setTimeout(() => {
const details = getCrystalDetails(structure);
if (details) {
detailsContainer.innerHTML = `
<div class="flex flex-col md:flex-row gap-8">
<div class="md:w-1/2">
<img src="${details.image}" alt="${details.title}" class="w-full rounded-lg shadow-md mb-4">
<div class="grid grid-cols-2 gap-4 mb-4">
<div class="bg-blue-50 p-3 rounded-lg">
<p class="text-sm text-blue-600 font-medium">Atomes/maille</p>
<p class="text-xl font-bold text-blue-800">${details.atomsPerCell}</p>
</div>
<div class="bg-purple-50 p-3 rounded-lg">
<p class="text-sm text-purple-600 font-medium">Compacité</p>
<p class="text-xl font-bold text-purple-800">${details.compactness}</p>
</div>
</div>
</div>
<div class="md:w-1/2">
<h2 class="text-2xl font-bold text-indigo-800 mb-4">${details.title}</h2>
<div class="prose prose-indigo max-w-none">
${details.description}
</div>
<div class="mt-6">
<h3 class="font-semibold text-lg text-indigo-700 mb-2">Métaux exemplaires</h3>
<div class="flex flex-wrap gap-2">
${details.examples.map(ex => `
<span class="bg-gray-100 text-gray-800 text-sm px-3 py-1 rounded-full">${ex}</span>
`).join('')}
</div>
</div>
</div>
</div>
`;
} else {
detailsContainer.innerHTML = `
<div class="text-center py-8">
<i data-feather="alert-circle" class="w-12 h-12 text-red-500 mx-auto mb-4"></i>
<h2 class="text-2xl font-bold text-indigo-800 mb-2">Structure inconnue</h2>
<p class="text-gray-600 mb-4">La structure "${structure}" n'est pas reconnue.</p>
<a href="index.html" class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-md inline-flex items-center">
<i data-feather="home" class="mr-2"></i>
Retour à l'accueil
</a>
</div>
`;
}
feather.replace();
}, 1000);
}
function getCrystalDetails(structure) {
const details = {
'cubique-simple': {
title: 'Cubique Simple',
image: 'http://static.photos/science/640x360/1',
atomsPerCell: 1,
compactness: '52%',
examples: ['Polonium'],
description: `
<p>La structure cubique simple (CS) est la plus élémentaire des structures cristallines. Elle se compose d'un atome à chaque sommet d'un cube.</p>
<p>Dans cette structure, chaque atome a 6 voisins immédiats (coordination 6). La compacité est relativement faible (52%), ce qui signifie que 52% du volume de la maille est occupé par les atomes.</p>
<p>Le paramètre de maille (a) est égal à deux fois le rayon atomique (r) : a = 2r</p>
`
},
'cubique-centree': {
title: 'Cubique Centrée',
image: 'http://static.photos/science/640x360/2',
atomsPerCell: 2,
compactness: '68%',
examples: ['Fer α', 'Chrome', 'Tungstène'],
description: `
<p>La structure cubique centrée (CC) possède un atome à chaque sommet du cube et un atome au centre de la maille.</p>
<p>Chaque atome a 8 voisins immédiats (coordination 8). La compacité est de 68%, plus élevée que la structure cubique simple.</p>
<p>Relation entre le paramètre de maille (a) et le rayon atomique (r) : a√3 = 4r</p>
`
},
'cubique-faces-centrees': {
title: 'Cubique Faces Centrées',
image: 'http://static.photos/science/640x360/3',
atomsPerCell: 4,
compactness: '74%',
examples: ['Cuivre', 'Aluminium', 'Or', 'Argent'],
description: `
<p>La structure cubique faces centrées (CFC) possède des atomes aux sommets et au centre de chaque face du cube.</p>
<p>Chaque atome a 12 voisins immédiats (coordination 12). C'est l'une des structures les plus compactes avec une compacité de 74%.</p>
<p>Relation entre le paramètre de maille (a) et le rayon atomique (r) : a√2 = 4r</p>
`
},
'hexagonale-compacte': {
title: 'Hexagonale Compacte',
image: 'http://static.photos/science/640x360/4',
atomsPerCell: 6,
compactness: '74%',
examples: ['Magnésium', 'Zinc', 'Titane α'],
description: `
<p>La structure hexagonale compacte (HC) est formée par l'empilement compact de couches d'atomes disposés selon un réseau hexagonal.</p>
<p>Comme la CFC, chaque atome a 12 voisins immédiats (coordination 12) et la compacité est de 74%. La différence réside dans la séquence d'empilement des plans atomiques.</p>
<p>La maille élémentaire est un prisme droit à base losange (maille rhomboédrique).</p>
`
}
};
return details[structure.toLowerCase()];
}
});
});
function updateCalculator(structure) {
let resultsHTML = '';
let atomsPerCell = 0;
let compactness = 0;
let description = '';
switch(structure) {
case 'cubique-simple':
atomsPerCell = 1;
compactness = 0.52;
description = "Chaque atome aux sommets est partagé entre 8 mailles.";
break;
case 'cubique-centree':
atomsPerCell = 2;
compactness = 0.68;
description = "Contient un atome central en plus des atomes aux sommets.";
break;
case 'cubique-faces-centrees':
atomsPerCell = 4;
compactness = 0.74;
description = "Atomes aux sommets et centres des faces du cube.";
break;
case 'hexagonale-compacte':
atomsPerCell = 6;
compactness = 0.74;
description = "Empilement compact de couches hexagonales.";
break;
}
resultsHTML = `
<div class="w-full">
<h3 class="text-xl font-semibold text-indigo-700 mb-2">${structure.replace('-', ' ').toUpperCase()}</h3>
<div class="space-y-2">
<div>
<span class="font-medium">Atomes par maille:</span>
<span class="ml-2 bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-sm">${atomsPerCell}</span>
</div>
<div>
<span class="font-medium">Compacité:</span>
<span class="ml-2 bg-purple-100 text-purple-800 px-2 py-1 rounded-full text-sm">${compactness}</span>
</div>
<p class="text-gray-600 text-sm mt-2">${description}</p>
</div>
</div>
`;
resultsContainer.innerHTML = resultsHTML;
}
// Navigation for crystal cards - each card will navigate to its detail page
const crystalCards = document.querySelectorAll('.crystal-card');
crystalCards.forEach(card => {
card.addEventListener('click', function() {
const structure = this.getAttribute('data-structure');
window.location.href = `details.html?structure=${structure}`.toLowerCase();
});
});
}); |