日期:2014-05-16 浏览次数:20354 次
<img src="aaa.jpg" orgurl="aaa-big.jpg"/>//图片添加一个orgurl属性,就是他的实际路径
$(function(){
$('img').click(function(){
var url = $(this).attr('orgurl');//如果不想添加orgurl路径或者说src属性就是实际的路径这里可以改成$(this).attr('src')
showBigImage(url,$(this));
});
})
function showBigImage(url,obj){
var maxWidth = 500;
var offset = obj.offset();
var start = {
width:obj.attr('width')
------解决方案--------------------
parseInt(obj.css('width')),
height:obj.attr('height')
------解决方案--------------------
parseInt(obj.css('height'))
}
$('<div></div>')
.attr('id', 'div_img_cover')
.css({ 'position': 'absolute', 'top': '0', 'left': '0', 'z-index': 9999,
'width': "100%",
'height': getWaitHeight(),
'text-align': 'center',
'font': 'bold 24px arial',
'background-repeat': 'no-repeat',
'background-position': 'center',
'background-attachment': 'fixed',
'opacity':0.8,
'background':'#000'
})
.appendTo('body');
var img = new Image();
$(img).css(start);
if(img.attachEvent){
img.attachEvent('onload',imgLoaded)
}else{
img.addEventListener('load',imgLoaded,false);
}
img.src = url;
function imgLoaded(){
var imgWidth = img.width,imgHeight = img.height;
var newWidth = imgWidth > maxWidth ? maxWidth : imgWidth;
var newHeight = imgHeight/imgWidth*newWidth
var end = {
width:parseInt(newWidth),
height