0

I have an input inside div element. The input is hidden by default and should be visible when mouse will be over container. Upon any keydown event the input should be hidden. Obviously user have to click on input field to entry text.

Here is my plnkr

 var container = $('#container');
 var flicker = $('#flicker').hide();
  var log = $('#log');
  container.on('mouseenter', function() {
    flicker.show();
    log.prepend('<div>mouseenter</div>');
  });
  flicker.on('keydown', function() {
    flicker.hide();
    setTimeout(function() {
      flicker.show();
    }, 4000);
  })

It works perfectly on Chrome, but fails on Firefox (OS x). On Firefox the input field doesn't disappeared, and works undesirable.

Any suggestion?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Alexey Sh.
  • 1,734
  • 2
  • 22
  • 34

1 Answers1

0

It seems to be a firefox bug.

I figured out the way. It's quite simple. Just use visibility: hidden instead of display: none. Say use flicker.addClass('hidden') instead of flicker.hide() or something like this.

The another approach is to off mouseenter event after flicker.hide() and enable again after 150ms. But it looks a bit ugly because of setTimeout.

The css example.

The css approach works nicely in firefox, chrome, safari, opera. But be aware of the difference between display: none and visibility: hidden.

Community
  • 1
  • 1
Alexey Sh.
  • 1,734
  • 2
  • 22
  • 34