Click through div to underlying elements

后端 未结 16 2373
逝去的感伤
逝去的感伤 2020-11-21 06:19

I have a div that has background:transparent, along with border. Underneath this div, I have more elements.

Curre

16条回答
  •  我寻月下人不归
    2020-11-21 06:46

    I currently work with canvas speech balloons. But because the balloon with the pointer is wrapped in a div, some links under it aren't click able anymore. I cant use extjs in this case. See basic example for my speech balloon tutorial requires HTML5

    So I decided to collect all link coordinates from inside the balloons in an array.

    var clickarray=[];
    function getcoo(thatdiv){
             thatdiv.find(".link").each(function(){
                     var offset=$(this).offset();           
                     clickarray.unshift([(offset.left),
                                         (offset.top),
                                         (offset.left+$(this).width()),
                                         (offset.top+$(this).height()),
                                         ($(this).attr('name')),
                                         1]);
                                         });
             }
    

    I call this function on each (new) balloon. It grabs the coordinates of the left/top and right/down corners of a link.class - additionally the name attribute for what to do if someone clicks in that coordinates and I loved to set a 1 which means that it wasn't clicked jet. And unshift this array to the clickarray. You could use push too.

    To work with that array:

    $("body").click(function(event){
              event.preventDefault();//if it is a a-tag
              var x=event.pageX;
              var y=event.pageY;
              var job="";
              for(var i in clickarray){
                  if(x>=clickarray[i][0] && x<=clickarray[i][2] && y>=clickarray[i][1] && y<=clickarray[i][3] && clickarray[i][5]==1){
                     job=clickarray[i][4];
                     clickarray[i][5]=0;//set to allready clicked
                     break;
                    }
                 }
              if(job.length>0){   
                 // --do some thing with the job --
                }
              });
    

    This function proofs the coordinates of a body click event or whether it was already clicked and returns the name attribute. I think it is not necessary to go deeper, but you see it is not that complicate. Hope in was enlish...

提交回复
热议问题