How to animate the opacity of an element on mouse hover using jQuery

  2493 views   2 years ago jQuery

Use the jQuery animate() method

You can use the jQuery animate(), mouseenter() and mouseleave() methods in combination with the CSS opacity property to animate the opacity of an element on mouse hover.

Let's try out the following example to understand how it basically works:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery Animate Opacity on Hover</title>
        padding: 0;
        list-style: none;
    ul li {
        float: left;        
        margin: 10px; 
    ul li a img{
        opacity: 0.3;
<script src=""></script>
                opacity: "1"
                opacity: "0.3"
        <li><a href="#"><img src="club.jpg" alt="Club Card"></a></li>
        <li><a href="#"><img src="diamond.jpg" alt="Diamond Card"></a></li>
        <li><a href="#"><img src="spade.jpg" alt="Spade Card"></a></li>
        <li><a href="#"><img src="heart.jpg" alt="Heart Card"></a></li>


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]