首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery淡入/淡出在第一次悬停时不起作用

问Jquery淡入/淡出在第一次悬停时不起作用
EN

Stack Overflow用户
提问于 2013-07-13 00:20:09
回答 2查看 985关注 0票数 1

我正在尝试使用淡入淡出jquery插件。昨天在这里的其他人的帮助下,我让它几乎完美地工作了。但是,当我第一次将鼠标悬停在div上时,效果上的淡入淡出效果似乎不起作用。它在第二次和随后的悬停之后工作。而且淡出效果似乎一点也不起作用。

http://jsfiddle.net/c6gRp/4/

注意:当你将鼠标悬停在步骤1上时,不会发生任何事情,但当你将鼠标悬停在其他步骤上时,颜色块应该会淡入/淡出。我更多的是一个设计师,所以我不确定为什么动画没有在第一次悬停时发生。这是编写JS代码的正确方式吗?

代码语言:javascript
复制
$(document).ready(function () {

    $("div.secure").hover(
        function() {
            $("div.secure-hover").stop(true, true, true).fadeIn('slow');
        },
        function() {
            $("div.secure-hover").stop(true, true, true).fadeOut('slow');
        }
    );

    $("div.cash").hover(
        function() {
            $("div.steps-hover.cash-hover").stop(true, true, true).fadeIn('slow');
        },
        function() {
            $("div.steps-hover.cash-hover").stop(true, true, true).fadeOut('slow');
        }
    );

    $("div.credit").hover(
        function() {
            $("div.credit-hover").stop(true, true, true).fadeIn('slow');
        },
        function() {
            $("div.credit-hover").stop(true, true, true).fadeOut('slow');
        }
    );

});

谢谢你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-13 01:51:56

在你的css上,你有像这样的"div.cash:hover you . -hover -hover“

代码语言:javascript
复制
div.default, div.cash:hover div.cash-hover, div.secure:hover div.secure-hover, div.credit:hover div.credit-hover{
    margin: 0;
    padding: 0;
    width: 960px;
    text-align: center;
    height: 180px;
    position: absolute; 
    top: 234px;
    display: block;
    left: 0;
    z-index: 3;
    right: 0px;
    cursor: auto;
}     

它仅当您将鼠标悬停在元素div.cash上时才设置属性width,height,...etc,如果您像这样更改它的话

代码语言:javascript
复制
div.default, div.cash-hover,div.secure-hover, div.credit-hover{
    margin: 0;
    padding: 0;
    width: 960px;
    text-align: center;
    height: 180px;
    position: absolute; 
    top: 234px;
    display: block;
    left: 0;
    z-index: 3;
    right: 0px;
    cursor: auto;
}
//set all -hover to display none
div.cash-hover, div.secure-hover, div.credit-hover {
    display: none;
}

您从一开始就设置了div.ash-hover的属性,这样$("div.cash").hover就可以为不透明http://jsfiddle.net/c6gRp/6/设置动画效果

票数 2
EN

Stack Overflow用户

发布于 2013-07-13 00:40:33

您没有为div.online-hover指定任何内容。

代码语言:javascript
复制
$("div.online").hover(
function () {
    $("div.online-hover").stop(true, true, true).fadeIn('slow');
},
function () {
    $("div.online-hover").stop(true, true, true).fadeOut('slow');
});

http://jsfiddle.net/c6gRp/5/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17619465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档