Skip to content

rtheunissen/tailorfit

Repository files navigation

TailorFit

Positioning plugin that supports arbitrary expressions

Usage

    $('#parent > img').load(function(){
        // maxWidth, maxHeight, maintain aspect ratio
        $(this).tailorfit({
                maxWidth  : this.width,
                maxHeight : this.height,
                ratio     : this.width / this.height
        });
    });

You can also use expressions to evaluate a value.

For example: max-width: 0.8*w-(200-h/4) or max-width: h / 2 - 20, where w and h are the parent's width and height.

Note: (expr) = expression, using (w, h, +, -, *, /, ^, %)

Available options:

  • max-width (expr)
  • max-height (expr)
  • aspect-ratio (expr)
  • x-offset (expr)
  • y-offset (expr)
  • h-position (left | center | right)
  • v-position (top | center | bottom)
  • rounding-method (round | floor | ceiling)
  • overflow (contain | crop)

About

jQuery plugin that allows you to fit elements (like images) within their containers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published