JavaScript-浮动广告

来源:互联网 发布:耽美文知乎 编辑:程序博客网 时间:2024/05/17 03:35
<img id="float" style="position:absolute" src="http://img.baidu.com/img/logo-zhidao.gif" /><script>var xPos = 0, yPos = 0, step = 1, yon = 0, xon = 0;var img = document.getElementById("float");function changePos() {var width = document.body.clientWidth;var height = document.body.clientHeight;var Hoffset = img.offsetHeight;var 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);}setTimeout('changePos()', 30);}window.onload = changePos;</script>

原创粉丝点击