Javascript 如何在jQuery中检测两个div何时发生冲突?禁止拖动div

Javascript 如何在jQuery中检测两个div何时发生冲突?禁止拖动div,javascript,jquery,html,css,collision,Javascript,Jquery,Html,Css,Collision,我到处都在网上搜索,想找到一种方法来检测两个div是否相互碰撞,但是,我找到的所有东西都是特定于插件或拖动的。我相当了解jQuery和自学!我在做一个游戏,一块饼干跳过牛奶杯。我试图让它检测到它们水平碰撞,但也能在我跳的时候检测到 以下是我的代码片段供参考: html: jQuery: $("#hand1").css({float:'right',"margin-top":"480px"}); $("#Cookie2").css({float:"left","margin- left"

我到处都在网上搜索,想找到一种方法来检测两个div是否相互碰撞,但是,我找到的所有东西都是特定于插件或拖动的。我相当了解jQuery和自学!我在做一个游戏,一块饼干跳过牛奶杯。我试图让它检测到它们水平碰撞,但也能在我跳的时候检测到

以下是我的代码片段供参考:

html:


jQuery:

 $("#hand1").css({float:'right',"margin-top":"480px"});
 $("#Cookie2").css({float:"left","margin-
 left":"400px",position:"absolute","margin-
 top":"25px",height:"510.5px",width:"580px"});

var hide= function() {
$("#hand1").hide();
}
$("#hand1").click(function(){
$("#milk").animate({marginRight:"900"},3000);
$("#Cookie").hide();
};
$("#Cookie2").show();
$("#milk").show();
move=1;
hide();

  if(move == 1){

  $("#Cookie2").css({width:"200px",height:"200",
  bottom:"0",position:"fixed"});
    $(window).keydown(function(e){
    if(e.keyCode==32){
    for (var i=1; i<=1; i++) {
    $("#Cookie2").animate({bottom:300},{
    duration:500,
    start:function(){
    console.log("start");

  },
    complete:function(){
      console.log("end");

    }
  });


  $("#Cookie2").animate({bottom:0},500);
}}})



}});
css({float:'right','margintop:'480px}); $(“#Cookie2”).css({float:“left”,“margin- 左“:“400px”,位置:“绝对”,“边距”- 顶部:“25px”,高度:“510.5px”,宽度:“580px”}; var hide=function(){ $(“#hand1”).hide(); } $(“#hand1”)。单击(函数(){ $(“#牛奶”)。制作动画({marginRight:“900”},3000); $(“#Cookie”).hide(); }; $(“#Cookie2”).show(); $(“#牛奶”).show(); move=1; 隐藏(); 如果(移动==1){ $(“#Cookie2”).css({宽度:“200px”,高度:“200”, 底部:“0”,位置:“固定”}); $(窗口).keydown(函数(e){ 如果(e.keyCode==32){ 对于(var i=1;i
 $("#hand1").css({float:'right',"margin-top":"480px"});
 $("#Cookie2").css({float:"left","margin-
 left":"400px",position:"absolute","margin-
 top":"25px",height:"510.5px",width:"580px"});

var hide= function() {
$("#hand1").hide();
}
$("#hand1").click(function(){
$("#milk").animate({marginRight:"900"},3000);
$("#Cookie").hide();
};
$("#Cookie2").show();
$("#milk").show();
move=1;
hide();

  if(move == 1){

  $("#Cookie2").css({width:"200px",height:"200",
  bottom:"0",position:"fixed"});
    $(window).keydown(function(e){
    if(e.keyCode==32){
    for (var i=1; i<=1; i++) {
    $("#Cookie2").animate({bottom:300},{
    duration:500,
    start:function(){
    console.log("start");

  },
    complete:function(){
      console.log("end");

    }
  });


  $("#Cookie2").animate({bottom:0},500);
}}})



}});