zShowBox 图片放大展示jquery版 兼容性

2020-05-23 06:08:22易采站长站整理

zsb_img_url = $(‘#zsb-‘ + current).attr(‘href’);
zsh_img(‘#zsb_img’, zsb_img_url, pagesize, current, zcounter);
return false;
});
$(‘#zsb_bg,#zsb_img’).click(function () {
$(‘#zsb_bg,#zsb_img’).unbind(‘click’);
$(‘#zsb_bg,#zsb’).fadeOut(400, function () { $(this).remove(); });
return false;
});
}
return false;
});
}
function zsh_img(img_id, zsb_img_url, pagesize, current, zcounter) {
$(‘#zsb_prev,#zsb_next’).hide();
//动态获取图片的宽度和高度的像素值
// //IE下,ajax会缓存,导致onreadystatechange函数没有被触发,所以需要加一个随机数
$(img_id).attr(‘src’, zsb_img_url+ ‘?t=’ + Math.random()).load(function () {
var img_w,img_h;
var x = pagesize[0] – 100, y = pagesize[1] – 100;
//imgReady 图片头数据加载就绪事件 – 更快获取图片尺寸
imgReady(zsb_img_url, function (){
img_w=this.width; img_h=this.height;
});
// img_w = $(this).width(), img_h = $(this).height();
if (img_w > x) {
img_h = img_h * (x / img_w);
img_w = x;
if (img_h > y) {
img_w = img_w * (y / img_h);
img_h = y;
}
} else if (img_h > y) {
img_w = img_w * (y / img_h);
img_h = y;
if (img_w > x) {
img_h = img_h * (x / img_w);
img_w = x;
}
}
var marginleft = -(img_w / 2 + 5) + ‘px’,
margintop = -(img_h / 2 + 5) + ‘px’;
img_w = img_w + ‘px’, img_h = img_h + ‘px’;
$(this).css({ “width”: img_w, “height”: img_h }).fadeIn(600).parent().css({ “margin-left”: marginleft, “margin-top”: margintop }).prev().css(“background-image”, “none”);
if (current > 0){ $(‘#zsb_prev’).show();}
if (current < zcounter – 1){ $(‘#zsb_next’).show();}
});
}
function zsb_getPageSize() {
var de = document.documentElement;
var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
arrayPageSize = [w, h];
return arrayPageSize;
}
var loadingimg = (function loadingimg() { //获取loading图片url
var i = 0, got = -1, url, len = document.getElementsByTagName(‘script’).length;
while (i <= len && got == -1) {
url = document.getElementsByTagName(‘script’)[i].src;
got = url.indexOf(‘/zshowbox.js’);
i++;
}
return url.replace(‘/zshowbox.js’, ‘/zshowbox-loading.gif’);
})();

图片头数据加载就绪事件 – 更快获取图片尺寸

/**
* 图片头数据加载就绪事件 – 更快获取图片尺寸
* @version 2011.05.27
* @author TangBin