判断拖放

复制代码
function check(obj1, obj2) {    //判断元素被拖放到指定元素内
    var widht = document.body.clientWidth,
        height = person.offsetHeight,
        obj1Left = obj1.offsetLeft,
        obj1Top = obj1.offsetTop,
        obj1Right = widht - obj1Left - obj1.offsetWidth,
        bj1Bottom = height - obj1Top - obj1.offsetHeight,
        obj2Left = obj2.offsetLeft,
        obj2Top = obj2.offsetTop,
        obj2Right = widht - obj2Left - obj2.offsetWidth,
        bj2Bottom = height - obj2Top - obj2.offsetHeight;
      
    if(obj1Left < obj2Left && obj1Right < obj2Right && obj1Top < obj2Top && bj1Bottom < bj2Bottom){
      return true
    }else{
      return false
    }
  }
复制代码

思路,获取盒子总宽高,  再获取obj1 & obj2 上下左右距离      最后判断obj2是否在obj1里面    是返回true    不是返回false

posted @   阿|明  阅读(85)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示