If you're looking to add some flair to your website, I suggest creating a second image file and using JavaScript to change the image source attribute on hover. This will not only brighten up your design but also allow for more creative possibilities beyond just adjusting brightness levels.
While it may seem like a simple task, let me walk you through it step by step. Since you're already familiar with basic CSS hover effects, I'll focus on the JavaScript aspect.
Your HTML structure likely resembles the following (with a added class
to the img
tag and a link to the JavaScript file):
<div class="hello">
<img class="play" src="https://i.ibb.co/HBbfCGF/play.png">
<span>Button</span>
</div>
<script src="script.js"></script>
To achieve the desired effect of changing the src=""
attribute of the <img>
tag upon hovering over the entire <div>
, you'll need to utilize the addEventListener() and setAttribute() methods.
let hello = document.querySelector('.hello');
hello.addEventListener('mouseover', function(){
let img = document.querySelector('.play');
img.setAttribute('src', 'path/to/the/second/file.png');
});
hello.addEventListener('mouseout', function(){
let img = document.querySelector('.play');
img.setAttribute('src', 'https://i.ibb.co/HBbfCGF/play.png');
});