<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 09: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>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 (标签-STM32|关键词-智能小车)
- ¥20 关于#stm32#的问题,请各位专家解答!
- ¥15 (标签-python)
- ¥15 第一个已完成,求第二个做法
- ¥20 搭建awx,试了很多版本都有错
- ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
- ¥15 activiti工作流问题,求解答
- ¥15 有人写过RPA后台管理系统么?
- ¥15 Bioage计算生物学年龄
- ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?