Home
Image Effects
Here
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE6+ Opr9+
jQuery Image Magnify v1.11 Author:
Feb 8th, 11 (v1.11): Fixed bug that caused script to not work in newever versions of jQuery (ie: v1.4.4). Only .js file changed. Description: jQuery Image Magnify enables any image on the page to be magnified by a desired factor when clicked on, via a sleek zoom in/out effect. The enlarged image is centered on the user's screen until dismissed. It works on both images with and without explicit width/height attributes defined. This means you can take a large image that by default would look out of place when shown, shrink it using explicit width/height attributes, then enable users to magnify it on demand to its original dimensions when the image is clicked on using this script. This script is extremely easy to set up- to enable the "magnify"
effect on any image, just give it a CSS class of " Demos Magnify by 3x, duration=0.5 second:
Magnify by 3.5x, duration=0.5 second:
Reapplying magnification to image after each image change:
Simply add the below code inside the <HEAD> section of the page: The above code references two external files which you should download below (right click, and select "Save As"):
Step 2: Then, to apply enable the magnify effect on an image
just insert a CSS class of " <img src="ocean.gif"
class="magnify" style="width:200px; height:150px" /> If your image contains explicit width/height attributes, then the script will magnify the image relative to those dimensions. Typically this is what you want to do- shrink a rather large image on the page and allow the user to magnify it only on demand. On the other hand if your image doesn't contain explicit width/height attributes, then its natural dimensions will be used as the basis of the magnification. The default magnification power, among a few other settings, are set globally at the top of jquery.imageWarp.js, which you can customize: dsettings: { A Available Image attributesYou can easily specify a different magnification and animation
duration for a specific image that deviates from the global default, by
inserting special attributes inside the image. Beside the prerequisite CSS class
of "
Links that expand a particular "magnify" imageFor image that carry the CSS class " <img id="sarah" src="girl.gif" class="imagewarp" data-magnifyby="5" style="width:200px; height:150px" /> The following arbitrary link will also magnify the above when the link is clicked: <a href=#" rel="magnify[sarah]">Zoom in on Sarah</a> The syntax is simply Here's an example:
|
| HTML Attribute | Description |
magnifyby: "number" |
Same as attribute counterpart above. |
magnifyto: "number" |
Same as attribute counterpart above. If
defined overrides magnifyby setting above. |
magnifyduration: "number" |
Same as attribute counterpart above. |
thumbdimensions: [width, height] |
Informs the script of the image's "thumbnail"
dimensions before the image is enlarged. This is required when you're
calling imageMagnify() on an image that doesn't have any
explicit dimensions defined (either via CSS or scripting) at the time of
calling imageMagnify() on it. This can happen for images
that are dynamically added to the page or has just had its src
property updated, in which the new image's thumbnail dimensions may be
different from the old one's. For example:var
myimg=document.createElement("img") |
Lets see a practical example now. Lets say you want to apply the
magnify effect to an image that can be changed via a drop down menu. With each
image change it's necessary to reapply the magnify effect to the image again, as
both its src and dimensions will have changed. So we call imageMagnify()
on the image each time the image is changed inside our code:
<form>
<select id="imageselect">
<option>Select a Picture and click to enlarge</option>
<option>Amsterdam 1</option>
<option>Amsterdam 2</option>
<option>Amsterdam 3</option>
<option>Amsterdam 4</option>
</select>
</form>
<img id="imagebox" src="amster1.jpg" class="magnify" data-magnifyby="2"
style="width:200px" />
<script type="text/javascript">
var imagebox=document.getElementById("imagebox")
var imageselect=document.getElementById("imageselect")
var imagelist=["amster1.jpg", "amster2.jpg", "amster3.jpg", "amster4.jpg"]
imageselect.onchange=function(){
if (this.selectedIndex!=0){
imagebox.src=imagelist[this.selectedIndex-1]
jQuery(imagebox).imageMagnify({
magnifyby: 2
})
}
}
</script>
The result: