关于对象的offsetWidht和offsetHeight
来源:互联网 发布:上海灵娱网络怎么样 编辑:程序博客网 时间:2024/05/18 02:38
<!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=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">...
function $(id)
...{
return document.getElementById(id);
}
function sImgd()
...{
$("ximg").src= $("setimg").options[$("setimg").selectedIndex].value;
}
function getW()
...{
$("imgWidth").value = $("getValue").value;
$("imgHeight").value = $("getValue").value* $("ximg").offsetHeight/$("ximg").offsetWidth;
$("ximg").width = $("imgWidth").value;
$("ximg").height = $("imgHeight").value;
}
</script>
</head>
<body>
<select id="setimg" onchange="sImgd()">
<option>选择</option>
<option value='http://www.doulaicha.com/images/logo1.jpg'>pic1 </option>
<option value='http://www.doulaicha.com/images/logo1.jpg'>pic2 </option>
<option value='http://www.doulaicha.com/images/logo1.jpg'>pic3 </option>
<option value='http://www.yibahuo.net.cn/images/logo1.jpg'>pic4 </option>
<option value='http://www.yibahuo.net.cn/images/logo1.jpg'>pic5 </option>
</select>
<input type=text size=5 name='getValue' id="getValue"> <input type=submit value='设宽' name='theW' onclick="getW()">
<input type=text name=imgWidth id="imgWidth"> <input type=text name=imgHeight id="imgHeight">
<a href="http://www.doulaicha.com"><img id="ximg" src="" /></a>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">...
function $(id)
...{
return document.getElementById(id);
}
function sImgd()
...{
$("ximg").src= $("setimg").options[$("setimg").selectedIndex].value;
}
function getW()
...{
$("imgWidth").value = $("getValue").value;
$("imgHeight").value = $("getValue").value* $("ximg").offsetHeight/$("ximg").offsetWidth;
$("ximg").width = $("imgWidth").value;
$("ximg").height = $("imgHeight").value;
}
</script>
</head>
<body>
<select id="setimg" onchange="sImgd()">
<option>选择</option>
<option value='http://www.doulaicha.com/images/logo1.jpg'>pic1 </option>
<option value='http://www.doulaicha.com/images/logo1.jpg'>pic2 </option>
<option value='http://www.doulaicha.com/images/logo1.jpg'>pic3 </option>
<option value='http://www.yibahuo.net.cn/images/logo1.jpg'>pic4 </option>
<option value='http://www.yibahuo.net.cn/images/logo1.jpg'>pic5 </option>
</select>
<input type=text size=5 name='getValue' id="getValue"> <input type=submit value='设宽' name='theW' onclick="getW()">
<input type=text name=imgWidth id="imgWidth"> <input type=text name=imgHeight id="imgHeight">
<a href="http://www.doulaicha.com"><img id="ximg" src="" /></a>
</body>
</html>
上面这个例子就是用offsetWidth和offsetHeight取得对象的宽和高。
offsetWidth是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变。
offsetHeight:获取对象相对于版面或由父坐标
- 关于对象的offsetWidht和offsetHeight
- 关于clientHeight、offsetHeight 和 scrollHeight
- offsetHeight和clientHeight的区别
- IE和FF下document.body对象的clientHeight,offsetHeight,scrollHeight的差别
- IE和FF下document.body对象的clientHeight,offsetHeight,scrollHeight的差别
- IE和FF下document.body对象的clientHeight,offsetHeight,scrollHeight的差别
- document.body 的 clientHeight、offsetHeight 和 scrollHeight
- 令人头晕的clientHeight、offsetHeight和scrollHeight
- offset、offsetLeft,offsetWidth和offsetHeight的使用方法
- 关于clientHeight、offsetHeight、scrollHeight
- 关于clientHeight、offsetHeight、scrollHeight
- 关于 clientHeight 、offsetHeight 、scrollHeight
- 关于clientHeight、offsetHeight、scrollHeight
- 关于clientHeight、offsetHeight、scrollHeight
- 关于clientHeight、offsetHeight、scrollHeight
- 关于clientHeight、offsetHeight、scrollHeight
- 关于offsetTop与offsetHeight的区别以及使用方法
- clientHeight、offsetHeight和scrollHeight
- 程序员的七种武器
- jquery使用方法简介
- sap视频教程
- spring + ibatis jpetstore 摘要
- 编写类String的构造函数,析构函数和赋值函数
- 关于对象的offsetWidht和offsetHeight
- vb6 GUid 生成
- Apache Tomcat 5.5 Servlet/JSP 容器安装 TOMCAT
- 中国地震带的分布
- 在spring2.5中无法使用dwr2
- 猴子摘桃程序
- 表格里的斜线,类似课程表的斜线
- 表格里的斜线,类似课程表的斜线
- SVG显示中文的设置