<div id="img" onmouseover="clearInterval(interval)" onmouseout="interval = setInterval('changePos()', delay)" align="middle">
<a href="#" ></a><br><span class="reset" onclick="clearInterval(interval);img.style.visibility = 'hidden'">关闭 X</span>
</div>
<script type="text/javascript">
var xPos=300;
var yPos=200;
var step=1;
var delay=16;
var height=0;
var Hoffset=0;
var Woffset=0;
var yon=0;
var xon=0;
var pause=false;
var interval;
changePos("img") ;
function changePos(objName)
{
var thediv=document.getElementById(objName);
thediv.style.position="absolute";
thediv.style.left=parseInt(window.screen.availWidth*Math.random()) + "px";
thediv.style.top=parseInt(window.screen.availHeight*Math.random()) + "px";
thediv.setAttribute("xDir",1);
thediv.setAttribute("yDir",1);
window.setInterval("randPosition(" + objName + ")","18","JavaScript");
}
function randPosition(obj)
{
var x=parseInt(obj.style.left);
if(x>=1500)
obj.setAttribute("xDir",-1);
if(x<=0)
obj.setAttribute("xDir",1);
x+=parseInt(obj.getAttribute("xDir"));
var y=parseInt(obj.style.top);
if(y>=700)
obj.setAttribute("yDir",-1);
if(y<=0)
obj.setAttribute("yDir",1);
y+=parseInt(obj.getAttribute("yDir"));
obj.style.left=x +"px";
obj.style.top =y +"px";
}
function start() {
img.style.visibility = "visible";
interval = setInterval('changePos()', delay);
}
start();
</script >
鼠标指向漂浮中的图片后,图片静止,怎么加静止代码?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 斯洛文尼亚旅游 2017-09-18 01:05关注
<div id="img" style="position: absolute; left: 2px; top: 43px;visibility :visible;" onmouseover="clearInterval(interval)" onmouseout="start()" align="middle"> <a href="#"></a><br><span class="reset" onclick="clearInterval(interval);img.style.visibility = 'hidden'">关闭 X</span> </div> <script type="text/javascript"> var xPos = 300; var yPos = 200; var step = 1; var delay = 1000; var height = 0; var Hoffset = 0; var Woffset = 0; var yon = 0; var xon = 0; var pause = false; var interval; changePos("img"); function changePos(objName) { var thediv = document.getElementById(objName); thediv.style.position = "absolute"; thediv.style.left = parseInt(window.screen.availWidth * Math.random()) + "px"; thediv.style.top = parseInt(window.screen.availHeight * Math.random()) + "px"; thediv.setAttribute("xDir", 1); thediv.setAttribute("yDir", 1); //不要这句,要不没次执行都会起动新计时器了 //interval = window.setInterval("randPosition('" + objName + "')", "18", "JavaScript"); } function randPosition(obj) { var x = parseInt(obj.style.left); if (x >= 1500) obj.setAttribute("xDir", -1); if (x <= 0) obj.setAttribute("xDir", 1); x += parseInt(obj.getAttribute("xDir")); var y = parseInt(obj.style.top); if (y >= 700) obj.setAttribute("yDir", -1); if (y <= 0) obj.setAttribute("yDir", 1); y += parseInt(obj.getAttribute("yDir")); obj.style.left = x + "px"; obj.style.top = y + "px"; } function start() { img.style.visibility = "visible"; interval = setInterval('changePos("img")', delay); } start(); </script>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 二维码被拦截如何处理
- ¥15 怎么解决LogIn.vue中多出来的div
- ¥15 优博讯dt50巴枪怎么提取镜像
- ¥30 在CodBlock上用c++语言运行
- ¥15 求C6748 IIC EEPROM程序固化烧写算法
- ¥50 关于#php#的问题,请各位专家解答!
- ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
- ¥15 TMUXHS4412如何防止静电,
- ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
- ¥20 机械振动学课后习题求解答