Mouse event issue for absolute div position

I have a list of mouseover images that should show some information. Problem - mouse events are not a trigger for an information div.

#team_div{
  display:block;
  position:relative;
}

#pop_div{
  width:300px;
  padding:5px;
  height:200px;
  overflow:hidden;
  border:2px solid #ccc;
  background:#fefefe;
  position:absolute;
  display:none;
}

#pop_div img{ 
  margin:10px;
  display:block;
  float:left;
}

.

<div id="team_div" class="team_div_loading">
<div id="pop_div"></div>
<table>

  list of images

</table>
</div>

.

$('#team_div > table img').hover(function() {
  var top = this.parentNode.offsetTop; 
  var left = this.parentNode.offsetLeft; 
  var img =$(this).attr('src');
  var id =$(this).attr('id');
  var content = $("#" + id + "p").html();
  $("#pop_div").show();
  $("#pop_div").css('top', top-11 +'px');
  $("#pop_div").css('left', left-12 +'px');
  $("#pop_div").html('<img src="' + img + '"/>' + content );
  $("#pop_div").fadeIn(700);
});

$("#pop_div").mouseout(function(){
  $("this").hide();
});

In this function, if is called to display on hover, none of the mouse events are fired for pop_div.

I appreciate your suggestions.

+3
source share
1 answer

Firstly, you cannot use in an element, use a div or ul li structure for this, I did this by inserting img tags in

<div class="imageDiv"></div>

and edit the jquery function with

$('#team_div>.imageDiv img').hover(function () {
        var top = this.parentNode.offsetTop;
        var left = this.parentNode.offsetLeft;
        var img = $(this).attr('src');
        var id = $(this).attr('id');
        var content = $("#" + id + "p").html();
        $("#pop_div").show();
        $("#pop_div").css('top', top - 11 + 'px');
        $("#pop_div").css('left', left - 12 + 'px');
        $("#pop_div").html('<img src="' + img + '"/>' + content);
        $("#pop_div").fadeIn(700);
    });

jquery. , , .

0

Source: https://habr.com/ru/post/1713333/


All Articles