diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd6dade --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*~ +*.swp + +# OS generated files # +###################### +.DS_Store +ehthumbs.db +Icon +Thumbs.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..0e7463a --- /dev/null +++ b/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); \ No newline at end of file diff --git a/Source/elCollide.js b/Source/elCollide.js new file mode 100644 index 0000000..677fa19 --- /dev/null +++ b/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)); + } +}); \ No newline at end of file diff --git a/collide.png b/collide.png new file mode 100644 index 0000000..79294e2 Binary files /dev/null and b/collide.png differ diff --git a/package.yml b/package.yml new file mode 100644 index 0000000..87eeebe --- /dev/null +++ b/package.yml @@ -0,0 +1,6 @@ +name: elCollide +author: jnbdz +category: Utilities +tags: [collide, collision, detect, element] +demo: http://jsfiddle.net/ +current: 0.1 \ No newline at end of file