Problem with jQuery mouseleave firing when container has select box

后端 未结 9 2248
一整个雨季
一整个雨季 2021-02-13 23:47

I have a two containers -- one is nested inside of another. When I hover over the parent, I want the child container to appear. When I mouseout, I want the child container to f

9条回答
  •  Happy的楠姐
    2021-02-13 23:56

    Since mouseleave and mouseenter events are non-standard you can get such lags here and there. The only method I can suggest to fix that is using some hacks. Here is http://jsfiddle.net/mPDcu/1/ improved version of you code.

    var selectOpened = false;
    $('#select-grind-type').click(function(e){
        selectOpened = !selectOpened;
        e.stopPropagation();
    });
    $('body').click(function(){
        if (selectOpened) {
            selectOpened = false;
        }
    })
    $('#parent-container').on("mouseenter", function() {
        var $this = $(this),
            $selectOptionsContainer = $this.find('#child-container');
        $selectOptionsContainer.stop().fadeTo('slow', 1.0);
    }).live("mouseleave", function(e) {
        if (!selectOpened) {
            var $this = $(this),
                $selectOptionsContainer = $this.find('#child-container');
            $selectOptionsContainer.stop().hide();   
        }
    });
    

提交回复
热议问题