// zoomi - A zoom for images ~ Sean Catchpole - Version 0.9 (function($){ $.fn.zoomi = function() { $(this).filter("img").each(function(){ if(!this.z) { $(this).zoom1().mouseover(function(){ //$(this).parent().parent().parent().siblings().children(".zoom2").hide(); //ajout sb bug de plusieurs images qui restent ouvertes $(".zoom2").hide(); $(this).zoom2().show(); }); $(this.z).mouseout(function(){$(this).hide();}); } }); return this; } $.fn.zoom1 = function() { $(this).each(function(){ var e = this; $(e).css({'position':'relative','z-index':'8'}).after(''); e.z = e.nextSibling; /*sb ancien bug sur la src de l'image $(e.z).removeClass("zoomi").addClass("zoom2").attr("src",e.alt || e.src) */ $(e.z).removeClass("zoomi").addClass("zoom2").attr("src", e.src) .css({'position':'absolute','z-index':'10'}); $(e.z).hide(); }); return this; } $.fn.zoom2 = function() { var s = []; this.each(function(){ var e = this; if(!e.z) e = $(e).zoom1()[0]; s.push(e.z); if(!e.z.complete) return; if(!e.z.width) { $(e.z).show(); e.z.width=e.z.width; $(e.z).hide(); } //ajout sb var pos_img = $(e).position(); var centreX = pos_img.left + ($(e).width() / 2); var new_img_left = (centreX - e.z.width / 2) //sb ancien + ajout d'une bordure //$(e.z).css({left:$(e).offsetLeft()-(e.z.width-e.scrollWidth)/2+'px', $(e.z).css({left: new_img_left+'px', top:$(e).offsetTop()-25-(e.z.height-e.scrollHeight)/2+'px', border: '1px solid #7a7a7a' }); }); return this.pushStack(s); } $.fn.offsetLeft = function() { var e = this[0]; if(!e.offsetParent) return e.offsetLeft; return e.offsetLeft + $(e.offsetParent).offsetLeft(); } $.fn.offsetTop = function() { var e = this[0]; if(!e.offsetParent) return e.offsetTop; return e.offsetTop + $(e.offsetParent).offsetTop(); } $(function(){ $('img.zoomi').zoomi(); }); })(jQuery);