GithubHelp home page GithubHelp logo

wangs1991 / jquery.imagefit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from periplox/jquery.imagefit

0.0 1.0 0.0 2.35 MB

A simple, lightweight plugin to make images fit anywhere and anyway.

Home Page: http://periplox.github.io/jquery.imagefit/

JavaScript 100.00%

jquery.imagefit's Introduction

jQuery ImageFit 1.0.2

A simple, lightweight plugin to make images fit anywhere and anyway.

##Demo: right here

##Usage

First, include the required files:

<script src='//code.jquery.com/jquery-1.10.2.min.js'></script>
<script src='jquery.imagefit.js'></script>

Then identify the elements you want to be affected. Let's say...

<div class="im"><img src="images/01.jpg" alt=""></div>
<div class="im"><img src="images/02.jpg" alt=""></div>
<div class="im"><img src="images/03.jpg" alt=""></div>
<div class="im"><img src="images/04.jpg" alt=""></div>
<div class="im"><img src="images/05.jpg" alt=""></div>
<div class="im"><img src="images/06.jpg" alt=""></div>

Finally set the ImageFit in the 'window load' event. If you detect visual flips or white margins then try doing it in both, the 'document ready' and the 'window load' events. There might be more accurate methods depending on how you apply the plugin.

$(window).load(function() {
	$('div.im').imagefit();
});

##Ignoring images

You can choose to ignore certain images, by defining a class name to use. This is especially helpful if using gallery thumbnails in jQuery Cycle2.

<img src="images/01.jpg" alt="" class="ignore">
<img src="images/02.jpg" alt="">

##Options

$('.cycle-slideshow').imagefit({
    ignore: '.ignore',
    mode: mode,
    force : 'true',
    halign : 'center',
    valign : 'middle',
    onStart: function (index, container, imagecontainer) {
	/* Some code */
    },
    onLoad: function (index, container, imagecontainer) {
    	/* Some code */
    },
    onError: function (index, container, imagecontainer) {
	/* Some code */
    }
});

And that would be it.

##Reference

Option Type Default Description
ignore string '' Takes a class name to use. e.g. '.ignore'.
mode string 'inside' It determines how images will be fitted inside the element: 'inside' or 'outside'.
halign string 'center' Horizontal alignment of the images relative to the container element: 'left', 'center' or 'right'.
valign string 'middle' Vertical alignment of the images relative to the container element: 'top', 'middle' or 'bottom'.
force bolean true Force resizing, even when image real size is smaller than container's.
onStart function Function to be executed on start event.
onLoad function Function to be executed on load event.
onError function Function to be executed on error.

jquery.imagefit's People

Contributors

periplox avatar

Watchers

 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.