如何在单击弹出窗口jQuery中应用悬停效果?

时间:2015-01-05 20:32:35

标签: javascript jquery hover click

我有一个最初隐藏的容器div,直到发生click事件。 div包含一个图像。我想在该图像上应用悬停效果,但是由于click事件被覆盖,我无法使悬停工作。以下是我的代码。

<div class='comment-click'>
    <div class="comment-product">
        <img class="checkered-shirt" src="img/checkered.jpg" />
        <div class="comment-hover-popup">
            <img class="popup-pic" src="img/Calvin_pic.png" />
            <h2 class="hover-title">Nautica</h2>
            <p class="description">Nautica Men's Hyannis Shoe</p>
            <input class="buy" id="buy" type="submit" value="Buy" />
            <p class="price">$55</p>
            <p class="hover-comment-command">Comment (2)</p>
            <img class="plus-icon" src="img/plus-icon.png" />
            <img class="check-icon" src="img/check-icon.png" />
        </div>
    </div>
    <h1>J.Crew</h1>
    <p class="product-description">J.Crew Plaid Button Down Shirt</p>
    <img class="comment-x" src="img/x.png" />
    <ul>
        <li>
            <div class="comment-one">
                <img src="img/Calvin_pic.png" />
                <p class="product-commenter">Paul Mickan </p>
                <p class="product-comment">Love this shirt #hipster</p>
            </div>
        </li>
        <li>
            <div class="comment-two">
                <img src="img/Calvin_pic.png" />
                <p class="product-commenter">Calvin Hemington </p>
                <input class="product-comment" type="text" name="Add a comment..." onfocus="if (this.value=='Add a comment...') this.value = ''" value="Add a comment..." /></a>
            <input class="comment-post" type="submit" value="Post" />
            </div>
        </li>
    </ul>
</div>

的jQuery

$('.hover-comment-command').click(function () {
    $('.comment-click').fadeIn();
    $('.comment-hover-popup').hide();
});

$('.comment-x').click(function () {
    $(".comment-click").fadeOut();
});

$(".checkered-shirt").hover(function () {
    $(this).find('.comment-hover-popup').fadeIn(300);
}, function () {
    $(this).find('.comment-hover-popup').hide();
});

1 个答案:

答案 0 :(得分:0)

$(this).siblings()功能

中使用$(this).find()代替hover()
$(".checkered-shirt").hover(function () {
    $(this).siblings('.comment-hover-popup').fadeIn(300);
}, function () {
    $(this).siblings('.comment-hover-popup').hide();
});

find()用于匹配元素的后代

siblings()适用于匹配元素的兄弟姐妹

See the docs here