Most efficient way to detect collision of two divs

前端 未结 2 1983
無奈伤痛
無奈伤痛 2021-01-27 12:23

I\'m using Jquery Collision to detect two objects overlapping each other. Here is a JSFiddle of the problem. (apologies for including jquery collision script in HTM

2条回答
  •  终归单人心
    2021-01-27 12:43

    Try this http://jsfiddle.net/aamir/y7PEp/6/

    $(document).ready(function () {
        var hit_list;
        var hits=0;
        $(".container").click(function () {
            var $this = $(this);
            function checkCollision() {
               //Test for collision
                hit_list = $(".menu").collision(".test");
                if (hit_list.length != 0) {
                    hits++;
                    $(".menu").html(hits+ ' hits');
                } 
            }
    
            $(".menu").stop().animate({
                left: "100px"
            }, 300, function () {
                checkCollision();
                $(".menu").animate({
                    left: "0"
                }, 800);
            });
        });
    });
    

提交回复
热议问题