简体   繁体   中英

jQuery mouseout if function

How can i set up a jQuery function that, when the user moves the mouse out of a div, will detect whether an input within the div is in focus and then change the div's opacity if it is not in focus?

So far I have tried using this code:

  $("#navbar").mouseout(function(event){
    if $(#navbarsearch.is( ":focus" )){
      //Animation Complete
    } else {
      $("#navbar").css('opacity', '0.8');
    }
  });

Using is(":focus") to determine if the input is focused should do the trick.

$('#div').on('mouseleave', function() {
    if($('input').is(":focus")) {
        $('input').fadeTo(duration, opacity);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM