How can I show a div only when hovering a menu item or the div?

后端 未结 2 1363
小鲜肉
小鲜肉 2021-01-07 15:10

I have items contained in an unordered list. I have hidden divs (using display:none;) outside of this list. When you hover over a list item, I would like the div to appear

2条回答
  •  日久生厌
    2021-01-07 15:55

    You can wrap the widgets in a div and attach a mouseleave event to it. This solution also uses the rel attibute to store the widget id: DEMO

    HTML

    Sub Title 1

    Lorem Ipsum Read More

    ...

    JS

    $('#main-menu a').mouseover(function() {
       var $this = $(this);
       var id = $this.attr('rel');
       var $currentWidget = $('#' + id);
       $currentWidget.show().siblings('.widget-container').hide();
    });
    $('#wrap').mouseleave(function() {
        $('.widget-container').hide();
    });
    

提交回复
热议问题