0

I have a little question.

 $('.item').mouseenter(function() {
    setTimeout(function() {
  $(this).find('.item-overlay').css('z-index', '-1');
}, 300);
}).mouseleave(function() {
  $(this).find('.item-overlay').css('z-index', '');
});

 <div class="item">
    <div class="item-overlay">
    </div>

    <iframe>...</iframe>

 </div>

Everything works fine, except one small thing. z-index isn't changing. Can you guys help me out with this? I've also tried with "next", "child", "find" - none worked :(

Jonas
  • 121,568
  • 97
  • 310
  • 388
Rafff
  • 1,510
  • 3
  • 19
  • 38

3 Answers3

5

this within the function you're passing setTimeout will be window, not the element. (this depends on how a function is called, not where it's used.)

You can save the this value the event handler got (or actually, as you're going to jQuery-wrap it, just do that with a var outside the setTimeout function), e.g.:

$('.item').mouseenter(function() {
    var $this = $(this);
    setTimeout(function() {
        $this.find('.item-overlay').css('z-index', '-1');
    }, 300);
    // ...
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

You need absolute positioning for ".item-overlay"

Lord Midi
  • 754
  • 1
  • 9
  • 25
0

I think this is out of your function. So, you can set var that = this; before setTimeout. And use that instead of this.

Callback stuff

MarshalSHI
  • 615
  • 1
  • 8
  • 17