Download script.js from Richard97200/mathmagic-munchkins: direct link, hf CLI and curl.
- Browser
- Download file 2.84 kB
-
https://huggingface.co/spaces/Richard97200/mathmagic-munchkins/resolve/main/script.js
- Command line
-
hf download hf://spaces/Richard97200/mathmagic-munchkins/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Richard97200/mathmagic-munchkins/resolve/main/script.js
2.84 kB
| // Initialize animations and effects | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Add sparkle effects randomly to magic elements | |
| const magicElements = document.querySelectorAll('.sparkle, .btn-magic'); | |
| magicElements.forEach(el => { | |
| el.addEventListener('mouseenter', () => { | |
| const sparkles = ['✨', '⭐', '🌟', '💫']; | |
| const randomSparkle = sparkles[Math.floor(Math.random() * sparkles.length)]; | |
| const spark = document.createElement('span'); | |
| spark.textContent = randomSparkle; | |
| spark.style.position = 'absolute'; | |
| spark.style.animation = 'sparkle 1s ease-out'; | |
| spark.style.pointerEvents = 'none'; | |
| spark.style.left = `${Math.random() * 100}%`; | |
| spark.style.top = `${Math.random() * 100}%`; | |
| el.appendChild(spark); | |
| setTimeout(() => spark.remove(), 1000); | |
| }); | |
| }); | |
| // Add floating effect to hero images | |
| const floatElements = document.querySelectorAll('.float-animation'); | |
| floatElements.forEach(el => { | |
| el.style.animationDelay = `${Math.random() * 2}s`; | |
| el.style.animationDuration = `${3 + Math.random() * 2}s`; | |
| }); | |
| // Age group selection animation | |
| const ageGroups = document.querySelectorAll('[href*="exercices.html?age="]'); | |
| ageGroups.forEach(group => { | |
| group.addEventListener('mouseenter', function() { | |
| this.querySelector('div').classList.add('animate-bounce'); | |
| }); | |
| group.addEventListener('mouseleave', function() { | |
| this.querySelector('div').classList.remove('animate-bounce'); | |
| }); | |
| }); | |
| }); | |
| // Simple math game function for demonstration | |
| function startMathGame(difficulty) { | |
| const operations = { | |
| easy: ['+', '-'], | |
| medium: ['+', '-', '×'], | |
| hard: ['+', '-', '×', '÷'] | |
| }; | |
| const num1 = Math.floor(Math.random() * (difficulty === 'easy' ? 10 : 20)) + 1; | |
| const num2 = Math.floor(Math.random() * (difficulty === 'easy' ? 10 : 20)) + 1; | |
| const operation = operations[difficulty][Math.floor(Math.random() * operations[difficulty].length)]; | |
| let question, answer; | |
| switch(operation) { | |
| case '+': | |
| question = `${num1} + ${num2}`; | |
| answer = num1 + num2; | |
| break; | |
| case '-': | |
| question = `${Math.max(num1, num2)} - ${Math.min(num1, num2)}`; | |
| answer = Math.max(num1, num2) - Math.min(num1, num2); | |
| break; | |
| case '×': | |
| question = `${num1} × ${num2}`; | |
| answer = num1 * num2; | |
| break; | |
| case '÷': | |
| const product = num1 * num2; | |
| question = `${product} ÷ ${num1}`; | |
| answer = num2; | |
| break; | |
| } | |
| return { question, answer }; | |
| } |