For this example, JavaScript is not strictly necessary, because the animations are handled via CSS. However, if you want to add interactive elements or conditional logic, you could do something like this:
javascript
document.querySelectorAll('.icon').forEach(icon => {
icon.addEventListener('mouseenter', () => {
// Add custom logic for when mouse enters
console.log('Mouse entered:', icon.id);
});
icon.addEventListener('mouseleave', () => {
// Add custom logic for when mouse leaves
console.log('Mouse left:', icon.id);
});
});
Additional Notes
This example uses FontAwesome for icons. To load FontAwesome, you might need to add the CDN link to the <head> section of your HTML:
The hover effect with translation and color change is achieved purely with CSS. JavaScript is left mostly as a placeholder for additional interactive behaviors or logging.
The animations are controlled via CSS transitions. You can adjust transform, color, and background-color to explore more advanced animations or effects.