Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbdz committed Apr 17, 2012
0 parents commit edf160f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
*~
*.swp

# OS generated files #
######################
.DS_Store
ehthumbs.db
Icon
Thumbs.db
13 changes: 13 additions & 0 deletions README.md
@@ -0,0 +1,13 @@
elCollide
===========

Detect if two elements are colliding.

![Screenshot](https://github.com/jnbdz/Element.serializeArea/raw/master/collide.png)

How to use
----------

The code is self explanatory. It will return true if the elements collide or false if the elements don't collide.

firstElement.elCollide(secondElement);
31 changes: 31 additions & 0 deletions Source/elCollide.js
@@ -0,0 +1,31 @@
/*
---
description: Detect if two elements are colliding.
authors:
- Jean-Nicolas Boulay (http://jean-nicolas.name/)
license:
- MIT-style license
requires:
- core/1.4: '*'
provides:
- Element.elCollide
...
*/

Element.implement({
elCollide: function(el2){
this.offsetBottom = this.offsetTop + this.offsetHeight;
this.offsetRight = this.offsetLeft + this.offsetWidth;
el2.offsetBottom = el2.offsetTop + el2.offsetHeight;
el2.offsetRight = el2.offsetLeft + el2.offsetWidth;

return !((this.offsetBottom < el2.offsetTop) ||
(this.offsetTop > el2.offsetBottom) ||
(this.offsetRight < el2.offsetLeft) ||
(this.offsetLeft > el2.offsetRight));
}
});
Binary file added collide.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions package.yml
@@ -0,0 +1,6 @@
name: elCollide
author: jnbdz
category: Utilities
tags: [collide, collision, detect, element]
demo: http://jsfiddle.net/
current: 0.1

0 comments on commit edf160f

Please sign in to comment.