2022-04-12 17:28:24
2024-01-11 15:10:57
======================代码可用,亲自测试过了
<html>
<head>
<meta charset='utf-8'>
<title>图片随便移动</title>
</head>
<body>
<div id="img" style="position:absolute;z-index=99;border:10px solid green;width:150px;height:150px;"> 我会随便移动 !
</div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var xPos = document.body.clientWidth-20;
var yPos = document.body.clientHeight/2;
var step = 2;
var delay = 5;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
var img = document.getElementById('img');
img.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
img.visibility = "visible";
interval = setInterval('changePos()', delay);
}
start();
img.onmouseover = function() {
clearInterval(interval);
interval = null;
}
img.onmouseout = function() {
interval = setInterval('changePos()', delay);
}
// End -->
</script>
</body>
</html>
2023-01-13 11:00:11
2021-02-15 20:02:10
2021-07-19 10:34:29