您的位置:首页 > Web前端 > JavaScript

js飘浮广告(可以为jpg.gif.flash文件)

2005-09-30 16:20 519 查看
<html>
<head>
<title>html-中国站长站www.chinaz.com</title>
</head>
<body>
<div id="img" style="position:absolute;z-index=99;">
<img src="jsimg/cursor.gif" onClick="pause_resume();" border="0" alt='img'>
</div>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var xPos = document.body.clientWidth-20;
var yPos = document.body.clientHeight/2;
var step = 1;
var delay = 5;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
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);
}
function pause_resume() {
if(pause) {
clearInterval(interval);
pause = false;
}else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
// End -->
</script>
</body>
</html>
<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: