根据url获取图片的高度和宽度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
无标题文档
</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
//GetImgInfo('ftp://101.231.222.22/files/2015/201512/20151215/20151215-144521-e27cbb00-5a7e-4e85-ac12-2eda920dbb45/20151215-144521-e27cbb00-5a7e-4e85-ac12-2eda920dbb45.jpg');
}
);
function imgLoadEvent(callback, url, param,obj) {//圖片事件加載
var img = new Image();
img.onreadystatechange = function () {
if (this.readyState == "complete") {
callback({ "w": img.width, "h": img.height });
}
}
img.onload = function () {
if (this.complete == true) callback({ "w": img.width, "h": img.height });
//alert(param);
if("x"==param){
$(obj).attr("width",img.width);
$(obj).attr("height",img.height);
$(obj).attr("onclick","changedaoxiao('d',this)");
}
if("d"==param){
$(obj).attr("width",img.width*0.5);
$(obj).attr("height",img.height*0.5);
$(obj).attr("onclick","changedaoxiao('x',this)");
//document.documentElement.clientWidth //IE中,设置浏览器高度
//document.documentElement.clientHeight //IE中,设置浏览器宽度
}
}
img.onerror = function () {
callback({ "w": 0, "h": 0 });
//current.autoSetImgSize(current,img,obj);
}
img.src = url;
}
function GetImgInfo(obj,param,url) {
var h = "";
var w = "";
imgLoadEvent(function (obj) {
h = parseInt(obj["h"]);
w = parseInt(obj["w"]);
//alert("w=" + w + ",h=" + h);
}, url,param,obj);
}
function changedaoxiao(param,obj){
//alert(obj.src);
GetImgInfo(obj,param,obj.src);
//alert(document.documentElement.clientHeight);
}
</script>
</head>
<body>
<img id="imgid" οnclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" οnclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" οnclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<br>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
无标题文档
</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
//GetImgInfo('ftp://101.231.222.22/files/2015/201512/20151215/20151215-144521-e27cbb00-5a7e-4e85-ac12-2eda920dbb45/20151215-144521-e27cbb00-5a7e-4e85-ac12-2eda920dbb45.jpg');
}
);
function imgLoadEvent(callback, url, param,obj) {//圖片事件加載
var img = new Image();
img.onreadystatechange = function () {
if (this.readyState == "complete") {
callback({ "w": img.width, "h": img.height });
}
}
img.onload = function () {
if (this.complete == true) callback({ "w": img.width, "h": img.height });
//alert(param);
if("x"==param){
$(obj).attr("width",img.width);
$(obj).attr("height",img.height);
$(obj).attr("onclick","changedaoxiao('d',this)");
}
if("d"==param){
$(obj).attr("width",img.width*0.5);
$(obj).attr("height",img.height*0.5);
$(obj).attr("onclick","changedaoxiao('x',this)");
//document.documentElement.clientWidth //IE中,设置浏览器高度
//document.documentElement.clientHeight //IE中,设置浏览器宽度
}
}
img.onerror = function () {
callback({ "w": 0, "h": 0 });
//current.autoSetImgSize(current,img,obj);
}
img.src = url;
}
function GetImgInfo(obj,param,url) {
var h = "";
var w = "";
imgLoadEvent(function (obj) {
h = parseInt(obj["h"]);
w = parseInt(obj["w"]);
//alert("w=" + w + ",h=" + h);
}, url,param,obj);
}
function changedaoxiao(param,obj){
//alert(obj.src);
GetImgInfo(obj,param,obj.src);
//alert(document.documentElement.clientHeight);
}
</script>
</head>
<body>
<img id="imgid" οnclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" οnclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" οnclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<br>
</body>
</html>