verge icon indicating copy to clipboard operation
verge copied to clipboard

Separate cushion from rectangle

Open ryanve opened this issue 12 years ago • 0 comments

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);
}

ryanve avatar Oct 15 '13 19:10 ryanve