CodeLab
Show Output
 
xxxxxxxxxx
42
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>jQuery Animate Opacity on Hover</title>
6
<style>
7
    ul{
8
        padding: 0;
9
        list-style: none;
10
    }
11
    ul li {
12
        float: left;        
13
        margin: 10px; 
14
    }
15
    ul li a img{
16
        opacity: 0.3;
17
    }
18
</style>
19
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
20
<script>
21
    $(document).ready(function(){
22
        $("a").mouseenter(function(){
23
            $(this).find("img").finish().animate({
24
                opacity: "1"
25
            });
26
        }).mouseleave(function(){
27
            $(this).find("img").finish().animate({
28
                opacity: "0.3"
29
            });
30
        });
31
    });
32
</script>
33
</head>
34
<body>
35
    <ul>
36
        <li><a href="#"><img src="/examples/images/club.jpg" alt="Club Card"></a></li>
37
        <li><a href="#"><img src="/examples/images/diamond.jpg" alt="Diamond Card"></a></li>
38
        <li><a href="#"><img src="/examples/images/spade.jpg" alt="Spade Card"></a></li>
39
        <li><a href="#"><img src="/examples/images/heart.jpg" alt="Heart Card"></a></li>
40
    </ul>
41
</body>
42
</html>
 

在微博、微信、公众号、小程序分享此示例。 如果您觉得有帮助,请给我们一个赞。