火狐、Google及びIEに対応するJavascript浮遊広告コード
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title> </title>
- </head>
-
- <body>
- <div id="oImg" style="position: absolute; z-index: 100; top: 0; left: 0; width: 125px; height: 125px; background: #FF9900; color: #FFFFFF;"><a href="http://www.bbs.zj.com/" target="_blank">
- <img src="http://ucenter.51cto.com/avatar.php?uid=6345222&size=middle" width="125px" height="125px" />
- </a></div>
- <script language="javascript" type="text/javascript">
- <!--
- var floatImg = document.getElementById("oImg");
- var delay = 10; // , ;
- var speed = 1; // , ;
- var flagX = 0;
- var flagY = 0;
-
- function toPixel(str1) {
- // px, 。
- var oldLen = str1.length;
- var newLen = oldLen - 2;
-
- str2 = str1.slice(0, newLen);
- str3 = parseInt(str2);
-
- return str3;
- }
-
- function flowImg() {
- var bWidth = document.body.clientWidth;
- var bHeight = document.body.clientHeight;
- var bLeft = document.body.scrollLeft;
- var bTop = document.body.scrollTop;
-
- var iWidth = floatImg.offsetWidth;
- var iHeight = floatImg.offsetHeight;
- var iLeft = toPixel(floatImg.style.left);
- var iTop = toPixel(floatImg.style.top);
-
- //
- if(iLeft < (bWidth - iWidth) && flagX == 0) {
- floatImg.style.left = (iLeft + speed) + "px";
- }
- else if(iLeft >= (bWidth - iWidth) && flagX ==0) {
- flagX = 1;
- }
- else if(iLeft > 0 && flagX == 1) {
- floatImg.style.left = (iLeft - speed) + "px";
- }
- else if(0 >= iLeft && flagX == 1) {
- flagX = 0;
- }
-
- //
- if(iTop < (bHeight - iHeight) && flagY == 0) {
- floatImg.style.top = (iTop + speed) + "px";
- }
- else if(iTop >= (bHeight - iHeight) && flagY ==0) {
- flagY = 1;
- }
- else if(iTop > 0 && flagY == 1) {
- floatImg.style.top = (iTop - speed) + "px";
- }
- else if(0 >= iTop && flagY == 1) {
- flagY = 0;
- }
- }
-
- var imgInterval = setInterval("flowImg()", delay);
- floatImg.onmouseover = function() {clearInterval(imgInterval);}
- floatImg.onmouseout = function() {imgInterval = setInterval("flowImg()", delay);}
- -->
- </script>
-
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- <p> </p>
- </body>
- </html>