jQuery figuring out if parent has lost 'focus'

后端 未结 7 1921
小鲜肉
小鲜肉 2020-12-16 05:39

I\'m stuck on figuring out the logic to make a drop down menu keyboard accessible.

The HTML is structured as such (extra class names used for clarity):



        
7条回答
  •  一个人的身影
    2020-12-16 06:30

    You can use event bubbling to check what has focus on the focusin event. I had success with the following code:

    
    $("li:has(ul.popUpMenu)").focusin(function(e) {
        $(this).children().fadeIn('slow');
      });
      $('body').focusin(function(e) {
        if (!$(e.target).parent().is('ul.popUpMenu li')) {
          $('ul.popUpMenu').fadeOut('slow');
        }
      });
    
    

    You could(should) probably make it more optimized, but it works.

提交回复
热议问题