<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript" defer>
var xPos=0;
var yPos=0;
var step=1;
var yon=0;
var xon=0;
img=document.getElementById("float");
function changPos(){
var width=document.body.clientWidth;
var height=document.body.clientHeight;
var Hoffset=img.offsetHeight;
var Woffset=img.offsetWidth;
img.style.left=xPos+document.body.scrollLeft;
img.style.top=yPos+document.body.scrollTop;
if(yon==0){
yPos=yPos+step;
}else{
yPos=yPos-step;
}
if(yPos <0){
yon=0;
yPos=0;
}
if(yPos>=(height-Hoffset)){
yon=1;
yPos=(height-Hoffset);
}
if(xon==0){
xPos=xPos+step;
}else{
xPos=xPos-step;
}
if(xPos <0){
xon=0;
xPos=0;
}
if(xPos>=(width-Woffset)){
xon=1;
xPos=(width-Woffset);
}
setTimeout("changPos()",30);
}
</script>
</head> <body onload=changPos()>
<div id="float" style="position:absolute;width:80px; height::80px;top:auto; left:auto; z-index:1">
<img width="80px" height="80px" src="1.jpg"/>
</div>
<img src="5.jpg" width="1024px" height="768px"> </body>
</html>
解决方案 »
- 根据xpath,js如何求该元素的值
- 帮我分析一下这个作用域原理
- 函数调用的程序问题
- JavaScript代码问题(初学者求助)
- http://www.sooch.cn/product/product.jhtml;jsessionid=61D4F6429C23D3D3DDAB4262B7AB7EFC?category003=01是怎么实现的
- 求救!一个添加项目的JS,下午就要做出来!
- JavaScript中如何使用COM对象?
- 表单信息验证.用户名,密码等.
- 二级联动的问题,联动已实现,但是我现在想从另个页面传个值过去,根据该值来更新联动,不知道如何下手
- (菜鸟问题)怎么样才能在一个页面里用一个submit同时提交两个form啊??
- 如何才能让右键菜单始终保持在最上层呢??
- 如何读取网页head中的内容,如keywords
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档 </title>
<script language="javascript">
var xPos=0;
var yPos=0;
var step=1;
var yon=0;
var xon=0;
var tid = null;
function changPos(){
var img=document.getElementById("float");
var width=document.body.clientWidth;
var height=document.body.clientHeight;
var Hoffset=img.offsetHeight;
var Woffset=img.offsetWidth;
img.style.left=xPos+document.body.scrollLeft;
img.style.top=yPos+document.body.scrollTop;
if(yon==0){
yPos=yPos+step;
}else{
yPos=yPos-step;
}
if(yPos <0){
yon=0;
yPos=0;
}
if(yPos>=(height-Hoffset)){
yon=1;
yPos=(height-Hoffset);
}
if(xon==0){
xPos=xPos+step;
}else{
xPos=xPos-step;
}
if(xPos <0){
xon=0;
xPos=0;
}
if(xPos>=(width-Woffset)){
xon=1;
xPos=(width-Woffset);
}
if(tid) clearTimeout(tid);
tid = setTimeout("changPos()",30);
}
window.onload=changPos;
</script>
</head> <body>
<div id="float" style="position:absolute;width:80px; height::80px;top:auto; left:auto; z-index:1">
<img width="80px" height="80px" src="1.jpg"/>
</div>
<img src="5.jpg" width="1024px" height="768px"> </body>
</html>
这句是我写错的setTimeout(:changPos():,30);
但绝对不是这句的原因
这两句有报错
var Hoffset=img.offsetHeight;
var Woffset=img.offsetWidth;
var img=document.getElementById("float");
不放在前面的话,用<script defer="true">