根据url获取图片的高度和宽度
来源:互联网 发布:mac app store更新不了 编辑:程序博客网 时间:2024/06/06 03:32
<!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" onclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" onclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" onclick="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" onclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" onclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<img id="imgid" onclick="changedaoxiao('d',this)" src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">
<br>
<br>
</body>
</html>
0 1
- 根据url获取图片的高度和宽度
- 获取图片宽度和高度的类
- 获取ALAset的图片宽度和高度
- 获取图片真实的宽度和高度
- Android获取图片的宽度和高度
- 获取图片宽度和高度
- 获取图片高度和宽度
- asp获取图片的高度和宽度的类
- getCompoundDrawables()和获取图片宽度和高度
- 一个获取图片宽度和高度的类
- 一个获取图片宽度和高度的类
- 一个获取图片宽度和高度的类
- asp一个获取图片宽度和高度的类
- js动态获取图片的宽度和高度像素值
- C# 获取图片文件的宽度和高度
- js 动态获取图片的宽度和高度像素值
- javascript获取动态加载图片的宽度和高度?
- PHP如何获取图片高度和宽度
- NS2 学习资料网站链接
- linux mv命令的用法
- tensorflow安装与测试
- linux内核中断
- 高级语言为什么不直接编译成机器码,而编译成汇编代码?
- 根据url获取图片的高度和宽度
- 数列特征
- jquery的ajax语法
- 2016/11/17 1001. 图的广度优先搜索
- oracle同义词
- 手残错误总结
- [BZOJ]1001: [BeiJing2006]狼抓兔子
- SQL中where 1=1 和 where1<>1
- 查找整数