0

当鼠标悬停在图片上时,我正在尝试使用 jquery 为 3 个 png 文件设置动画,我发现这个带有文本的示例。我尝试修改html:

<div class="img3"><img src=cat1.png></div>
<div class="img3"><img src=cat2.png></div>
<div class="img3"><img src=cat3.png></div>

但这不起作用。


<script src="jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
    $('.hover_me').hover(function () {
        $('.img5').fadeOut(5000, function () {
            $('.img4').fadeOut(5000, function () {
                $('.img3').fadeOut(5000);
            });
        });
    });
});
</script>


<link rel="stylesheet" href="style.css" type="text/css">

<body>
    <div class="hover_me">Hover me</div>
    <div class="container"> 
        <div class="img3">3</div>
        <div class="img4">4</div>
        <div class="img5">5</div>
    </div><!--/container-->
</body>

CSS:

.hover_me {
    color: red;
    font-weight: bold;
}

.container {
    border: 1px solid #000000;
    position: relative;
    display: block;
    width: 100px;
    height: 100px;
    margin: 0px auto;
}

.container div {
    position: absolute;
}

.img3 {
    display: block;
    width: 100px;
    height: 100px;
    background-color: #E5A932;
}

.img4 {
    display: block;
    width: 100px;
    height: 100px;
    background-color: #DC25ED;
}

.img5 {
    display: block;
    width: 100px;
    height: 100px;
    background-color: #15EFD6;
}
4

1 回答 1

0

这是你想要的 ?

我不知道你为什么不能让它工作。上面的代码本身可以完美运行。可能是您没有正确包含 jquery。你必须像这样包含 jquery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>

如果您的根目录中没有该文件。

在这里小提琴:http: //jsfiddle.net/hpZwZ/1/

于 2013-09-23T10:59:44.000 回答