Mouseout and mouseleave not working

前端 未结 3 1376
臣服心动
臣服心动 2021-01-27 12:58

Hi I am using mouseout and mouseleave methods but both are not working. I tried to fix it but cant find the solution. My code looks fine, it has no err

3条回答
  •  孤街浪徒
    2021-01-27 13:19

    The problem is that the events are not being caught because they are not exactly bubbling properly.

    Live depends on proper bubbling of events. I think the chosen plugin breaks the bubbling

    Try this:

    $(".chzn-select").chosen()
    $(function(){
        $('a').click(function(){
            $('.mydiv').addClass('redbrd')
    
            $('.redbrd').live('mouseover',function(){
                if($('#mmt').length == 0){
                    var htm= '
    some text
    '; $('body').append(htm); } }); $('.redbrd').live('mouseout',function(){ $('#mmt').remove(); }); }) })

    With added css:

    .mydiv{padding:10px;}
    

    This makes the div that you are mousing over large enough that you are not instantly entering and exiting it. To see this working in your current example, slowly approach the bottom right corner of the red border until you 'enter' the div in the minuscule white space that is between the select and the div. then move out. You will see it works as expected.

    I added the changes I mentioned to a fiddle. You can see it working there.

提交回复
热议问题