imgzr.js : jQuery image selector based on screen width

Update: january 17, 2012 : now with REAL screen orientation detection and browser resize.
Update:
 january 13, 2012 : now with screen orientation detection.

how to use

Include :

$(function () {
 $('body').imgzr();
});

It will look into the given element (here “body”) for image and change the src if needed.

Check the demo : http://dev.federalbureauofinhumanity.org/imgzr/ (last version is v0.2)

It has been tested under :

  • Chrome 16
  • Firefox 9
  • IE9
  • Ipad
  • Iphone

configuration

Prepare your images ! Your image should have the small image in src to prevent bandwith overcharging. Add data- with the well sized image. Example :

img src="./img/small.jpg" alt=""
 data-small="./img/small.jpg"
 data-medium="./img/medium.jpg"
 data-large="./img/large.jpg"

(Sorry, I dropped the “<” & “/>” because of the pre tag)

The default configuration is the following :

resolutions:{
 small:{min:0, max:480},
 medium:{min:480, max:768},
 large:{min:768, max:10000}
}

You can change this passing a new configuration to the function call :

$(function () {
 var config = {
 resolutions:{
 small:{min:0, max:1000},
 medium:{min:1000, max:10000},
 large:{min:10000, max:100000}
 }
 };
 $('body').imgzr(config);
});

license

This script is licensed under the terms of the WTF Public License (see here and here) :

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004 

 Copyright (C) 2004 Sam Hocevar  

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed. 

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 

  0. You just DO WHAT THE FUCK YOU WANT TO.

Contact

You can contact me at siegfried.ehretATgmail.com (replace AT with @) Please write “imgzr” or something in your subject.

Duck Duck Go Zero Info search box

Update : january 17, 2012 : this plugin has been slightly modified. I had problems with reserved words… My mistake !

I always wanted to do a jQuery plugin. Now, it’s done !

It is available on GitHub.

Last version is v0.3 : try it here.

This is a jQuery plugin for Duck Duck Go Zero-click Info API.
For those who are not familiar with Duck Duck Go, it’s my new favorite search engine. Go try it !

It provides a box with some basic info (like… From wolfram alpha, wikipedia etc.).

I will make some tests to make it better (but I don’t like tests… Sorry) and add more parameters soon.
Stay tuned !

And don’t forget to use Duck Duck Go !