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

Separate cushion from rectangle #5

Open
ryanve opened this issue Oct 15, 2013 · 0 comments
Open

Separate cushion from rectangle #5

ryanve opened this issue Oct 15, 2013 · 0 comments

Comments

@ryanve
Copy link
Owner

ryanve commented Oct 15, 2013

Internally I'm planning to separate rectangle cushioning from measuring. It could also be useful to have a public method (called .pad() or .cushion() or otherwise) that could adjust rectangles. Should this be exposed?

function pad(coords, cushion) {
    var o = {};
    cushion = typeof cushion == 'number' && cushion || 0;
    o.width = (o.right = coords.right + cushion) - (o.left = coords.left - cushion);
    o.height = (o.bottom = coords.bottom + cushion) - (o.top = coords.top - cushion);
    return o;
}

For use by .rectangle()

function rectangle(el, cushion) {
    el = el && !el.nodeType ? el[0] : el;
    if (!el || 1 !== el.nodeType) return false;
    return pad(el.getBoundingClientRect(), cushion);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant