/* jquery image magnify script v1.1 * this notice must stay intact for usage * author: dynamic drive at http://www.dynamicdrive.com/ * visit http://www.dynamicdrive.com/ for full source code * nov 16th, 09 (v1.1): adds ability to dynamically apply/reapply magnify effect to an image, plus magnify to a specific width in pixels. */ jquery.noconflict() jquery.imagemagnify={ dsettings: { magnifyby: 1.5, //default increase factor of enlarged image duration: 500, //default duration of animation, in millisec imgopacity: 0.2 //opacify of original image when enlarged image overlays it }, cursorcss: 'url(magnify.cur), -moz-zoom-in', //value for css's 'cursor' attribute, added to original image zindexcounter: 100, refreshoffsets:function($window, $target, warpshell){ var $offsets=$target.offset() var winattrs={x:$window.scrollleft(), y:$window.scrolltop(), w:$window.width(), h:$window.height()} warpshell.attrs.x=$offsets.left //update x position of original image relative to page warpshell.attrs.y=$offsets.top warpshell.newattrs.x=winattrs.x+winattrs.w/2-warpshell.newattrs.w/2 warpshell.newattrs.y=winattrs.y+winattrs.h/2-warpshell.newattrs.h/2 if (warpshell.newattrs.x winattrs.x+winattrs.w){//no space to the right? warpshell.newattrs.x=winattrs.x+5 } if (warpshell.newattrs.y0 && parseint($imgref.css('height'))>0 || options.thumbdimensions){ //if image has explicit width/height attrs defined jquery.imagemagnify.magnify($, $imgref, options) } else if (this.complete){ //account for ie not firing image.onload jquery.imagemagnify.magnify($, $imgref, options) } else{ $(this).bind('load', function(){ jquery.imagemagnify.magnify($, $imgref, options) }) } }) }; jquery.fn.applymagnifier=function(options){ //dynamic version of imagemagnify() to apply magnify effect to an image dynamically var $=jquery return this.each(function(){ //return jquery obj var $imgref=$(this) if (this.tagname!="img") return true //skip to next matched element }) }; //** the following applies the magnify effect to images with class="magnify" and optional "data-magnifyby" and "data-magnifyduration" attrs //** it also looks for links with attr rel="magnify[targetimageid]" and makes them togglers for that image jquery(document).ready(function($){ var $targets=$('.magnify') $targets.each(function(i){ var $target=$(this) var options={} if ($target.attr('data-magnifyto')) options.magnifyto=parsefloat($target.attr('data-magnifyto')) if ($target.attr('data-magnifyby')) options.magnifyby=parsefloat($target.attr('data-magnifyby')) if ($target.attr('data-magnifyduration')) options.duration=parseint($target.attr('data-magnifyduration')) $target.imagemagnify(options) }) var $triggers=$('a[rel^="magnify["]') $triggers.each(function(i){ var $trigger=$(this) var targetid=$trigger.attr('rel').match(/\[.+\]/)[0].replace(/[\[\]']/g, '') //parse 'id' from rel='magnify[id]' $trigger.data('magnifyimageid', targetid) $trigger.click(function(e){ $('#'+$(this).data('magnifyimageid')).trigger('click.magnify') e.preventdefault() }) }) })