# landscape-fit **Repository Path**: mirrors_Jam3/landscape-fit ## Basic Information - **Project Name**: landscape-fit - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-23 - **Last Updated**: 2026-03-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # landscape-fit [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges) Fit an element to specific dimensions, rotated according to the aspect ratio to maintain a fake "orientation lock". Similar to [canvas-fit](https://github.com/hughsk/canvas-fit), but doesn't handle canvas scaling for HiDPI displays. ![](http://i.imgur.com/SZZ5SN0.gif) ## Usage [![NPM](https://nodei.co/npm/landscape-fit.png)](https://www.npmjs.com/package/landscape-fit) ### resize = fit(element[, parent]) Creates a `resize` function for your `element`. Calling this function will resize the element to fit its parent. Here's a simple example to make your canvas update its dimensions when resizing the window: ``` javascript var fit = require('landscape-fit') var element = document.createElement('div') window.addEventListener('resize', fit(element), false) ``` You might want to override the `parent` element that the canvas should be fitting within: in which case, pass that element in as your second argument: ``` javascript window.addEventListener('resize', fit(element, window), false) ``` You can also pass your own dimensions via a callback like so: ``` javascript window.addEventListener('resize', fit(element, function (dims) { dims[0] = 100 dims[1] = 200 }), false) ``` ### `resize.parent = ` Dynamically change the element's `parent` element. Note that you still need to manually trigger a resize after doing this. ### `resize.parent = () => [width, height]` Instead of filling a given element, explicitly set its width and height. Note that you still need to manually trigger a resize after doing this. ## License MIT, see [LICENSE.md](http://github.com/jam3/landscape-fit/blob/master/LICENSE.md) for details.