【问题标题】:unable to get child element to fadein when hovering over parent element悬停在父元素上时无法让子元素淡入
【发布时间】:2013-09-13 15:43:04
【问题描述】:

我是 JQuery 新手,目前正在尝试让子元素淡入以在用户将鼠标悬停在父元素上时显示产品信息。

这是我运气不佳的情况:

jQuery:

$('.overlay-wrap').hover(function(){

    $('.product-overlay', this).fadeIn(2000, "swing");

    },

    $('.product-overlay', this).fadeOut("fast");

});

HTML:

<div class="overlay-wrap">
            <div class="product-overlay"><a href="#">Name of the product</a></div>
    </div>

CSS:

.overlay-wrap{
    position:relative;
    border:1px solid red;
    width:200px;
    height:200px;
}
    .product-overlay{
        position:absolute;
        bottom:0px;
        left:0px;
        background:#000;
        opacity:0.5;
        padding:5px;
        width:100%;
        display:none;
    }
    .product-overlay a{
        font-size:12px;
        line-height:20px;
    }

这是我目前所拥有的简化版JSFiddle

为什么当我将鼠标悬停在父元素上时子元素没有淡入?

【问题讨论】:

    标签: jquery hover fadein jquery-hover


    【解决方案1】:

    您没有为悬停停止事件创建适当的函数处理程序。

    jsFiddle Demo

    $('.overlay-wrap').hover(
        function () { $('.product-overlay', this).fadeIn(2000, "swing"); },
        function () { $('.product-overlay', this).fadeOut("fast");       }
                            );
    

    【讨论】:

      猜你喜欢
      • 2011-11-05
      • 1970-01-01
      • 2021-10-13
      • 2011-10-10
      • 2019-12-22
      • 2013-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多