简体   繁体   English

使div在悬停时可见

[英]make div visible on hover

I need to make div visible on hover 我需要使div在悬停时可见

$(document).ready(function () {
$('.carousel').hover(function () {

    $(this).parent().next('.semitransparentoverlay').fadeIn('200');

},

function () {
    $(this).parent().next('.semitransparentoverlay').fadeOut('200');
});

});

but on hover div becomes visible again and again 但在悬停div上一次又一次可见
http://jsfiddle.net/n8b65qbb/14/ http://jsfiddle.net/n8b65qbb/14/
How to prevent it and make div visible only once and then hide it on mouselive only once? 如何防止它并使div仅可见一次,然后在mouselive上将其隐藏一次?

If you do the hover on the parent instead, and move the overlay to within the wrapper, this will prevent the fading in of the overlay from triggering a second hover event. 如果改为在父对象上进行悬停,然后将叠加层移到包装器内,这将防止叠加层的淡入触发第二个悬停事件。

html, moving overlay inside of carousel-wrapper: html,在carousel-wrapper内部移动叠加层:

<div class="block-11 block-1">
    <div class="carousel-wrapper" id="carousel-1">
        <ul class="carousel clearfix">
            <li><img src="http://i.imgur.com/eTxMX2T.jpg" alt="" width="646" height="350"/></li>
        </ul>
    <div class="semitransparentoverlay">
        <input name="" type="button" value="Show all" class="btn-1"/>
    </div>
</div>

Jquery, targeting carousel-wrapper for hover: jQuery,将轮播包装器定位为悬停目标:

$(document).ready(function () {
    $('.carousel-wrapper').hover(function () {
        $(this).children('.semitransparentoverlay').fadeIn('200');
    },

    function () {
        $(this).children('.semitransparentoverlay').fadeOut('200');
    });

});

Updated link: http://jsfiddle.net/carasin/1po0acv6/2/ 更新的链接: http : //jsfiddle.net/carasin/1po0acv6/2/

Another option would be including and extra div just for hover event, before carousel-wrapper . 另一个选择是在carousel-wrapper之前,仅在悬停事件中包含和extra div。

$(document).ready(function () {
    $('.hover-block').hover(function () {

        $(this).siblings('.semitransparentoverlay').fadeIn('200');

    },

    function () {
        $(this).siblings('.semitransparentoverlay').fadeOut('200');
    });

});

Check fiddle: http://jsfiddle.net/benjasHu/d1wg3fe0/ 检查小提琴: http : //jsfiddle.net/benjasHu/d1wg3fe0/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM