Giter Site home page Giter Site logo

fitimg's Introduction

Fitimg

Fitimg is a jQuery plugin to make images "fit" to their containers. See the demo.

Fitimg

Requirements

  1. jQuery v1.8+
  2. The imagesLoaded plugin (v3+)

The imagesLoaded plugin is optional but Fitimg won't work very well without it. See Advanced section below.

Usage

Include the scripts and styles in your HTML head:

<link rel="stylesheet" href="jquery.fitimg.css" type="text/css" />

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="imagesloaded.js"></script>
<script src="jquery.fitimg.js"></script>

Then make sure your images have container divs wrapping them:

<div class="imgwrap">
	<img src="http://placekitten.com/400/200" alt="" />
</div>
<div class="imgwrap">
	<img src="http://placekitten.com/200/400" alt="" />
</div>
<div class="imgwrap">
	<img src="http://placekitten.com/300/150" alt="" />
</div>

Then simply hook up Fitimg:

<script>
$(document).ready(function(){
	$('.imgwrap').fitimg();
});
</script>

Advanced

Fitimg has an afterLoad event which is triggered after the image has been loaded and positioned. For example:

<script>
$(document).ready(function(){
	$('.imgwrap').fitimg({
		afterLoad: function(){
			// do something here...
		}
	});
});
</script>

Fitimg will add a fitimg-loaded class to images once they have been loaded and positioned. By default Fitvid uses opacity to hide the images, but to make sure you're images don't flash before Fitvid has loaded, you can help by making sure you're images have zero opacity. For example in CSS:

.imgwrap img { opacity: 0; }

If you are not using the imagesLoaded plugin you should use jQuery's $(window).load() event rather than $(document).ready(), to make sure the images have fully loaded.

Browser Compat

Fitimg works in all modern browsers (Chrome, Firefox, Safari, Opera) and in IE8+.

Credits

Fitimg was created by Gilbert Pellegrom from Dev7studios. Released under the MIT license.

fitimg's People

Contributors

gilbitron avatar

Watchers

 avatar  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.