Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit edf160f
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*~ | ||
*.swp | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
ehthumbs.db | ||
Icon | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
}); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: elCollide | ||
author: jnbdz | ||
category: Utilities | ||
tags: [collide, collision, detect, element] | ||
demo: http://jsfiddle.net/ | ||
current: 0.1 |