开发者

How to detect a div over another div with jQuery?

How to detect a div over another div with jQuery? any solution?? thanks for you answe开发者_如何学Cr


You can use the children selector. Note it travels only a single level down the dom for anything else use find

<div class="abc">

  <div class="def">Div 2</div>
  <div class="def">Div 3</div>

</div>

Somehow find the parent div.. using a class or id selector or choosing it smarlty by using first. last etc.

$(".abc").children().each(function(){
$(this).html("test");
});

or use a selector

$(".abc").children(":first").append("test2");

http://jsfiddle.net/fVQB8/ Does that help you?


To get this you can use the following code, if your one DIV is called i1 and the other div is called example Image1 - then you can get the offsetTop and offsetLeft positions and compare them.

    var y = document.getElementById('i1').offsetTop;
    var x = document.getElementById('i1').offsetLeft;


    var elementy = document.getElementById('image1').offsetTop;
    var elementx = document.getElementById('image1').offsetLeft;

    if (elementy == y) {
        if (elementx == x) {
            gameover();
        }
    }


You can try this or use $('#div').on('dragstart',function(evt)

var CardOnePosistion;
var MovedPosition;
        
$(function(){     
MovedPosition = $('#Moved').position();
CardOne = $('#CardOne').position();
 if (MovedPosition.left === CardOne.left && MovedPosition.top === CardOne.top) {
       alert("Div over another Div");
  } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜