Show child div on mouse hover of parent - needs javascript?

前端 未结 7 1999
悲哀的现实
悲哀的现实 2021-02-01 13:27

I need to show a div when you house over its parent (default is for the child div to be hidden). Is the only way to do this with javascript? Thanks

7条回答
  •  失恋的感觉
    2021-02-01 13:48

    I initially was using css solution above, but had to use jQuery because my child div contained an image which caused hover to flicker. Here we're displaying child when hovering over parent (if desktop screen size) on mouseenter and hiding it on mouseleave but only if now hovering over main page container, to minimize flickering:

    $(document).ready(function () {
        $(".parent-qtip").mouseenter(function () {
            if ($(window).width()>=1200)
                $(this).children(".child-qtip").show();
        });
        $(".parent-qtip").mouseleave(function () {
            if ($('.page-content').find('.container:hover').length)
                $('.child-qtip').hide();
        });
    });
    

提交回复
热议问题