GithubHelp home page GithubHelp logo

shitchell / fwoh Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 7 KB

A javascript library for adjusting elements to their parent's width or height based on aspect ratio

License: The Unlicense

JavaScript 100.00%

fwoh's Introduction

fwoh

A javascript library for adjusting elements to their parent's width or height, ensuring that they completely fill the parent while maintaining their aspect ratio

What It Does

This tool essentially resizes elements in the same manner as object-fit: contain, but without cropping the element once fit to its container. I wanted to be able to fit images inside of a div such that you could see as much of the image as possible, without letterbox-esque borders, while still being able to scroll to see the rest of the image (see this project for an example).

Compatibility

Tested on Chrome for Android, Chrome, Firefox, Safari, and a crappy SmartTV browser. The original intent was to be able to use it for a custom web-based screensaver on a TV using the somewhat feature-lacking web browsers found on SmartTV's/Xboxes/Wiis, etc... so it should be compatible with most every browser that runs Javascript. Feel free to let me know or send a pull request if you find a browser it doesn't work on!

Getting Started

Include the javascript file in your page

<script type="application/javascript" src="js/fwoh.js"></script>

Edit your HTML elements

  1. Add the "fwoh" class to an element
  2. ???
  3. Profit

Exempli Gratia

<div class="img-wrapper" style="width: 400px; height: 200px;">
  <img class="fwoh" src="img/profile.jpg" />
</div>

The <img> will be resized such that it expands to fill the wrapper while maintaining its aspect ratio.

If the image is 1920x768

This will adjust the <img> to 500x200, matching the parent's height and resizing the image's width to maintain its original ratio

If the image is 1280x720

This will adjust the <img> to 400x225, matching the parent's width and resizing the image's height to maintain its original ratio

fwoh's People

Contributors

shitchell avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.