jQuery/JavaScript collision detection

前端 未结 7 2151
情话喂你
情话喂你 2020-11-22 04:49

How to detect if two

elements have collided?

The two divs are simple coloured boxes travelling perpendicular to each other, so no complicate

7条回答
  •  旧巷少年郎
    2020-11-22 05:22

    I believe this is the easiest way: http://plugins.jquery.com/project/collidable

    Here is another one, in German: http://www.48design.de/news/2009/11/20/kollisionsabfrage-per-jquery-plugin-update-v11-8/

    I'd give those a try.

    --UPDATE--

    I can't really spend anytime on it right now, but i can when i get home if no one answers but you;d do something like:

    setInterval(function(){
                //First step would be to get the offset of item 1 and item 2
                //Second would be to get the width of each
                //Third would be to check if the offset+width ever overlaps
                    //the offset+width of the 2nd
                //Fourth would be, if so, do X or set a class...
            },10);
    

提交回复
热议问题