Giter Site home page Giter Site logo

adaptive-images's Introduction

Adaptive Image JS (jQuery Plugin)

The script adds basic adaptive image support for browsers. It helps you allow image assets to be dynamically swapped in and out via basic Media Querys

WHY SHOULD I USE THIS?

Responsive layouts are the new and big thing in web design, when a website is designed to be responsive it can dynamically resize itself to fit on a mobile phone using new techniques available in CSS3, meaning a truly one site fits all experience. The video and audio tags can also similarly be written in html to load different sized and quality content depending on the screen size and device. However the img has still not been updated, so mobiles are still forced to download full desktop sized resolution images, the images simply cannot adapt as it isn't part of the HTML Spec yet. Whilst there are proposals for this to happen, no browser implements it and most current solutions rely on a backend server. Adaptive Image JS provides a simple easy to use library with a fallback for browsers without Javascript.

HOW TO USE ADAPTIVE IMAGE JS

Add your image

All images you wish to be adaptive should be post-fixed with the adaptive namespace. For example:

<img:adaptive src="animage.png" />

You should provide a default source for this tag (you can provide a media query for this tag if you wish). Then inside this tag place any alternative versions you want to use along with the media queries in a media attribute. For example:

<img:adaptive src="Low-Res.png" media = "only screen and (max-width: 820px)">
	<source src="High-Res.png" media = "only screen and (min-width: 1100px)"/>
</img:adaptive>

Finally if you wish to provide a fallback for browsers without javascript then insert a standard img like you would normally bellow the alternative sources:

<img:adaptive src="Low-Res.png" media = "only screen and (max-width: 820px)">
	<source src="High-Res.png" media = "only screen and (min-width: 1100px)"/>
	<img src="Fallback.png"/>
</img:adaptive>

Add the Javascript

Then add the javascript into the body of the document

<script type="text/javascript" src="adaptiveimages.js" />

Limitations

The script only supports the Media Queries max-width, min-width in px units combined with the keyword 'and' ('or' is not supported).

  • Although you can mix media types with and without a Media Query in one stylesheet (i.e.: media="only screen and (max-width: 480px), handheld") or multiple media types with one or more media queries (i.e.: media="only screen and (min-width: 1025px) and (max-width: 1600px), only projection and (min-width: 1025px) and (max-width: 1600px)"), you can not use multiple media types with multiple different Media Queries (i.e.: media="only screen and (min-width: 1025px), only projection and (min-width: 1200px)" <- this will fail). To achieve this you have to add another image source.

    Demo


    Download


    CHANGELOG

    • 1.0 (30/04/2012)
      • First release

    LICENSE

    Copyright (C) 2010-2012, James Campbell & Alexander Farkas

    _Licensed under **BSD Opensource License** (free for personal and commercial use)_
    
  • adaptive-images's People

    Stargazers

     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.