Select DIV with highest z-index

后端 未结 4 1546
遇见更好的自我
遇见更好的自我 2021-01-18 09:50

Example code so I can start explaining this problem:

5
2
相关标签:
4条回答
  • 2021-01-18 10:31

    I'm sure you could use the stop event to gain access to the recently dragged item, i.e.:

    $('.selector').draggable({
       stop: function(event, ui) {
          $(event.target).addClass('justDragged');
       }
    });
    

    If you wish to see all functions/variables bound to event, you could use the following:

    var str = '';
    for (i in event) {
        str += i + ', ';
    }
    alert(str);
    

    This should give you a good indication of what's available to you in any number of jQuery callback params.

    0 讨论(0)
  • 2021-01-18 10:36

    In your place I would simply attach event onclick on each div. I think then Javascript or jQuery will automatically take into account zindex information and you will get event exactly on DIV where you clicked.

    0 讨论(0)
  • 2021-01-18 10:41

    I just figured out that there's a 'start dragging' event in .draggable. How silly of me.

    $("#window-"+id+".staticwindow.stwin").draggable({
    ...
        start: function(e, u){
            $(".window").removeClass('active');
            $(this).addClass('active');
        }
    });
    

    Although this approach of mine is not related to my original question anymore, atleast there's no looping. I'm not going to accept any answer because this seems to need a loop. (Although I'm slightly inclined to accept the answer by zarko-o because it lead me to think on events)

    Thanks everyone for your answers!

    0 讨论(0)
  • 2021-01-18 10:43

    You can always test against jQuery(".yourDivs").css("z-index") once you've added the class on all your divs.

    0 讨论(0)
提交回复
热议问题