').addClass('zoomPreload').css('visibility','hidden').html(settings.preloadText);
$('.zoomPad',el).append(this.node);
};
this.show = function () {
this.node.top = (smallimage.oh - this.node.height()) / 2;
this.node.left = (smallimage.ow - this.node.width()) / 2;
//setting position
this.node.css({
top: this.node.top,left: this.node.left,position: 'absolute',visibility: 'visible'
});
};
this.hide = function () {
this.node.css('visibility','hidden');
};
return this;
}
/*========================================================,| Lens
|---------------------------------------------------------:
| Lens over the image
`========================================================*/
function Lens() {
var $obj = this;
this.node = $('
').addClass('zoomPup');
//this.nodeimgwrapper = $("
").addClass('zoomPupImgWrapper');
this.append = function () {
$('.zoomPad',el).append($(this.node).hide());
if (settings.zoomType == 'reverse') {
this.image = new Image();
this.image.src = smallimage.node.src; // fires off async
$(this.node).empty().append(this.image);
}
};
this.setdimensions = function () {
this.node.w = (parseInt((settings.zoomWidth) / el.scale.x) > smallimage.w ) ? smallimage.w : (parseInt(settings.zoomWidth / el.scale.x));
this.node.h = (parseInt((settings.zoomHeight) / el.scale.y) > smallimage.h ) ? smallimage.h : (parseInt(settings.zoomHeight / el.scale.y));
this.node.top = (smallimage.oh - this.node.h - 2) / 2;
this.node.left = (smallimage.ow - this.node.w - 2) / 2;
//centering lens
this.node.css({
top: 0,left: 0,width: this.node.w + 'px',height: this.node.h + 'px',display: 'none',borderWidth: 1 + 'px'
});
if (settings.zoomType == 'reverse') {
this.image.src = smallimage.node.src;
$(this.node).css({
'opacity': 1
});
$(this.image).css({
position: 'absolute',display: 'block',left: -(this.node.left + 1 - smallimage.bleft) + 'px',top: -(this.node.top + 1 - smallimage.btop) + 'px'
});
}
};
this.setcenter = function () {
//calculating center position
this.node.top = (smallimage.oh - this.node.h - 2) / 2;
this.node.left = (smallimage.ow - this.node.w - 2) / 2;
//centering lens
this.node.css({
top: this.node.top,left: this.node.left
});
if (settings.zoomType == 'reverse') {
$(this.image).css({
position: 'absolute',top: -(this.node.top + 1 - smallimage.btop) + 'px'
});
}
//centering large image
largeimage.setposition();
};
this.setposition = function (e) {
el.mousepos.x = e.pageX;
el.mousepos.y = e.pageY;
var lensleft = 0;
var lenstop = 0;
function overleft(lens) {
return el.mousepos.x - (lens.w) / 2 < smallimage.pos.l;
}
function overright(lens) {
return el.mousepos.x + (lens.w) / 2 > smallimage.pos.r;
}
function overtop(lens) {
return el.mousepos.y - (lens.h) / 2 < smallimage.pos.t;
}
function overbottom(lens) {
return el.mousepos.y + (lens.h) / 2 > smallimage.pos.b;
}
lensleft = el.mousepos.x + smallimage.bleft - smallimage.pos.l - (this.node.w + 2) / 2;
lenstop = el.mousepos.y + smallimage.btop - smallimage.pos.t - (this.node.h + 2) / 2;
if (overleft(this.node)) {
lensleft = smallimage.bleft - 1;
} else if (overright(this.node)) {
lensleft = smallimage.w + smallimage.bleft - this.node.w - 1;
}
if (overtop(this.node)) {
lenstop = smallimage.btop - 1;
} else if (overbottom(this.node)) {
lenstop = smallimage.h + smallimage.btop - this.node.h - 1;
}
this.node.left = lensleft;
this.node.top = lenstop;
this.node.css({
'left': lensleft + 'px','top': lenstop + 'px'
});
if (settings.zoomType == 'reverse') {
if ($.browser.msie && $.browser.version > 7) {
$(this.node).empty().append(this.image);
}
$(this.image).css({
position: 'absolute',top: -(this.node.top + 1 - smallimage.btop) + 'px'
});
}
largeimage.setposition();
};
this.hide = function () {
img.css({
'opacity': 1
});
this.node.hide();
};
this.show = function () {
if (settings.zoomType != 'innerzoom' && (settings.lens || settings.zoomType == 'drag')) {
this.node.show();
}
if (settings.zoomType == 'reverse') {
img.css({
'opacity': settings.imageOpacity
});
}
};
this.getoffset = function () {
var o = {};
o.left = $obj.node.left;
o.top = $obj.node.top;
return o;
};
return this;
};
/*========================================================,| Stage
|---------------------------------------------------------:
| Window area that contains the large image
`========================================================*/
function Stage() {
var $obj = this;
this.node = $("
");
this.ieframe = $('
');
this.setposition = function () {
this.node.leftpos = 0;
this.node.toppos = 0;
if (settings.zoomType != 'innerzoom') {
//positioning
switch (settings.position) {
case "left":
this.node.leftpos = (smallimage.pos.l - smallimage.bleft - Math.abs(settings.xOffset) - settings.zoomWidth > 0) ? (0 - settings.zoomWidth - Math.abs(settings.xOffset)) : (smallimage.ow + Math.abs(settings.xOffset));
this.node.toppos = Math.abs(settings.yOffset);
break;
case "top":
this.node.leftpos = Math.abs(settings.xOffset);
this.node.toppos = (smallimage.pos.t - smallimage.btop - Math.abs(settings.yOffset) - settings.zoomHeight > 0) ? (0 - settings.zoomHeight - Math.abs(settings.yOffset)) : (smallimage.oh + Math.abs(settings.yOffset));
break;
case "bottom":
this.node.leftpos = Math.abs(settings.xOffset);
this.node.toppos = (smallimage.pos.t - smallimage.btop + smallimage.oh + Math.abs(settings.yOffset) + settings.zoomHeight < screen.height) ? (smallimage.oh + Math.abs(settings.yOffset)) : (0 - settings.zoomHeight - Math.abs(settings.yOffset));
break;
default:
this.node.leftpos = (smallimage.rightlimit + Math.abs(settings.xOffset) + settings.zoomWidth < screen.width) ? (smallimage.ow + Math.abs(settings.xOffset)) : (0 - settings.zoomWidth - Math.abs(settings.xOffset));
this.node.toppos = Math.abs(settings.yOffset);
break;
}
}
this.node.css({
'left': this.node.leftpos + 'px','top': this.node.toppos + 'px'
});
return this;
};
this.append = function () {
$('.zoomPad',el).append(this.node);
this.node.css({
position: 'absolute',zIndex: 5001
});
if (settings.zoomType == 'innerzoom') {
this.node.css({
cursor: 'default'
});
var thickness = (smallimage.bleft == 0) ? 1 : smallimage.bleft;
$('.zoomWrapper',this.node).css({
borderWidth: thickness + 'px'
});
}
$('.zoomWrapper',this.node).css({
width: Math.round(settings.zoomWidth) + 'px',borderWidth: thickness + 'px'
});
$('.zoomWrapperImage',this.node).css({
width: '100%',height: Math.round(settings.zoomHeight) + 'px'
});
//zoom title
$('.zoomWrapperTitle',position: 'absolute'
});
$('.zoomWrapperTitle',this.node).hide();
if (settings.title && zoomtitle.length > 0) {
$('.zoomWrapperTitle',this.node).html(zoomtitle).show();
}
$obj.setposition();
};
this.hide = function () {
switch (settings.hideEffect) {
case 'fadeout':
this.node.fadeOut(settings.fadeoutSpeed,function () {});
break;
default:
this.node.hide();
break;
}
this.ieframe.hide();
};
this.show = function () {
switch (settings.showEffect) {
case 'fadein':
this.node.fadeIn();
this.node.fadeIn(settings.fadeinSpeed,function () {});
break;
default:
this.node.show();
break;
}
if (isIE6 && settings.zoomType != 'innerzoom') {
this.ieframe.width = this.node.width();
this.ieframe.height = this.node.height();
this.ieframe.left = this.node.leftpos;
this.ieframe.top = this.node.toppos;
this.ieframe.css({
display: 'block',position: "absolute",left: this.ieframe.left,top: this.ieframe.top,zIndex: 99,width: this.ieframe.width + 'px',height: this.ieframe.height + 'px'
});
$('.zoomPad',el).append(this.ieframe);
this.ieframe.show();
};
};
};
/*========================================================,| LargeImage
|---------------------------------------------------------:
| The large detailed image
`========================================================*/
function Largeimage() {
var $obj = this;
this.node = new Image();
this.loadimage = function (url) {
//showing preload
loader.show();
this.url = url;
this.node.style.position = 'absolute';
this.node.style.border = '0px';
this.node.style.display = 'none';
this.node.style.left = '-5000px';
this.node.style.top = '0px';
document.body.appendChild(this.node);
this.node.src = url; // fires off async
};
this.fetchdata = function () {
var image = $(this.node);
var scale = {};
this.node.style.display = 'block';
$obj.w = image.width();
$obj.h = image.height();
$obj.pos = image.offset();
$obj.pos.l = image.offset().left;
$obj.pos.t = image.offset().top;
$obj.pos.r = $obj.w + $obj.pos.l;
$obj.pos.b = $obj.h + $obj.pos.t;
scale.x = ($obj.w / smallimage.w);
scale.y = ($obj.h / smallimage.h);
el.scale = scale;
document.body.removeChild(this.node);
$('.zoomWrapperImage',el).empty().append(this.node);
//setting lens dimensions;
lens.setdimensions();
};
this.node.onerror = function () {
alert('Problems while loading the big image.');
throw 'Problems while loading the big image.';
};
this.node.onload = function () {
//fetching data
$obj.fetchdata();
loader.hide();
el.largeimageloading = false;
el.largeimageloaded = true;
if (settings.zoomType == 'drag' || settings.alwaysOn) {
lens.show();
stage.show();
lens.setcenter();
}
};
this.setposition = function () {
var left = -el.scale.x * (lens.getoffset().left - smallimage.bleft + 1);
var top = -el.scale.y * (lens.getoffset().top - smallimage.btop + 1);
$(this.node).css({
'left': left + 'px','top': top + 'px'
});
};
return this;
};
$(el).data("jqzoom",obj);
};
//es. $.jqzoom.disable('#jqzoom1');
$.jqzoom = {
defaults: {
zoomType: 'standard',//innerzoom/standard/reverse/drag
zoomWidth: 300,//zoomWindow default width
zoomHeight: 300,//zoomWindow default height
xOffset: 10,//zoomWindow x offset,can be negative(more on the left) or positive(more on the right)
yOffset: 0,//zoomWindow y offset,can be negative(more on the left) or positive(more on the right)
position: "right",//zoomWindow default position
preloadImages: true,//image preload
preloadText: 'Loading zoom',title: true,lens: true,imageOpacity: 0.4,alwaysOn: false,showEffect: 'show',//show/fadein
hideEffect: 'hide',//hide/fadeout
fadeinSpeed: 'slow',//fast/slow/number
fadeoutSpeed: '2000' //fast/slow/number
},disable: function (el) {
var api = $(el).data('jqzoom');
api.disable();
return false;
},enable: function (el) {
var api = $(el).data('jqzoom');
api.enable();
return false;
},disableAll: function (el) {
jqzoompluging_disabled = true;
},enableAll: function (el) {
jqzoompluging_disabled = false;
}
};
})(jQuery);
还需要有Jquery.js
使用方法:
1.当页面导入的时候,载入 jQZoom 插件。
2.创建一个放图片的容器,指定一个a标记用于显示放大后的图片的一部分:
下面给一些基本的配置参数:
•zoomType,默认值:'standard',另一个值是'reverse',是否将原图用半透明图层遮盖。
•zoomWidth,默认值:200,放大窗口的宽度。
•zoomHeight,默认值:200,放大窗口的高度。
•xOffset,默认值:10,放大窗口相对于原图的x轴偏移值,可以为负。
•yOffset,默认值:0,放大窗口相对于原图的y轴偏移值,可以为负。
•position,默认值:'right',放大窗口的位置,值还可以是:'right','left','top','bottom'。
•lens,默认值:true,若为false,则不在原图上显示镜头。
•imageOpacity,默认值:0.2,当zoomType的值为'reverse'时,这个参数用于指定遮罩的透明度。
•title,默认值:true,在放大窗口中显示标题,值可以为a标记的title值,若无,则为原图的title值。
•showEffect,默认值:'show',显示放大窗口时的效果,值可以为: ‘show','fadein'。
•hideEffect,默认值:'hide',隐藏放大窗口时的效果: ‘hide','fadeout'。
•fadeinSpeed,默认值:'fast',放大窗口的渐显速度(选项: ‘fast','slow','medium')。
•fadeoutSpeed,默认值:'slow',放大窗口的渐隐速度(选项: ‘fast','medium')。
•showPreload,默认值:true,是否显示加载提示Loading zoom(选项: ‘true','false')。
•preloadText,默认值:'Loading zoom',自定义加载提示文本。
•preloadPosition,默认值:'center',加载提示的位置,值也可以为'bycss',以通过css指定位置。
样式的个性化当然也可以直接修改jqzoom.css文件。