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