Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element.inside #14

Open
jnbdz opened this issue Nov 9, 2015 · 0 comments
Open

Element.inside #14

jnbdz opened this issue Nov 9, 2015 · 0 comments
Labels

Comments

@jnbdz
Copy link
Member

jnbdz commented Nov 9, 2015

/*

---
description: Check if the first element is inside the second element.

authors:
  - Jean-Nicolas Boulay (http://jean-nicolas.com)

license:
  - MIT-style license

requires:
 - core/1.4:   '*'

provides:
  - Element.inside
...
*/

Element.implement({
inside: function(el2){
    var thisLeftX = this.offsetLeft;
    var thisLeftY = this.offsetTop;
    var thisRightX = (this.offsetWidth + this.offsetLeft);
    var thisRightY = (this.offsetTop + this.offsetHeight);
    var el2LeftX = el2.offsetLeft;
    var el2LeftY = el2.offsetTop;
    var el2RightX = (el2.offsetWidth + el2.offsetLeft);
    var el2RightY = (el2.offsetHeight + el2.offsetTop);

    return (((el2LeftY <= thisLeftY) &&
             (thisLeftY <= el2RightY)) &&
             ((el2LeftY <= thisRightY) &&
             (thisRightY <= el2RightY)) &&
             ((el2LeftX <= thisLeftX) &&
             (thisLeftX <= el2RightX)) &&
             ((el2LeftX <= thisRightX) &&
             (thisRightX <= el2RightX)));
}
});
@jnbdz jnbdz added the Proposal label Nov 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant