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

[原创]使用javascript制作漂浮的广告,在页面上自由飘转

2005-06-13 11:11 645 查看
floast.js原文件:

<!-- Begin
var xPos = 20;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
dd.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = dd.offsetHeight;
Woffset = dd.offsetWidth;
dd.style.left = xPos + document.body.scrollLeft;
dd.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() {
dd.visibility = "visible";
interval = setInterval('changePos()', delay);
}
function pause_resume() {
if(pause) {
clearInterval(interval);
pause = false;
}
else {
interval = setInterval('changePos()',delay);
pause = true;
}
}
start();
// End -->

html文件调用方法:
<div id=dd style="Z-INDEX: 1; LEFT: 4px; WIDTH: 100px; POSITION: absolute; TOP: 372px; HEIGHT: 100px">
<p align="center">
<a href="contact/guize.html"><img src="images/play.gif" border="0" width="195" height="240"></a></p>
</div>
<script language="JavaScript" src="js/float.js"></script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: