W3C标准漂浮代码鼠标上浮自动停止

符合W3C标准漂浮代码鼠标上浮自动停止

<script language=JavaScript>
document.write('<div id="myImg" style="z-index:1000;position: absolute; left: 0; top: 0">');
document.write('<a href="http://www.kukafei.cn/" target="_blank"><img border="0" src="漂浮图片地址"></a>');
document.write('</div>');

var myObj=document.getElementById("myImg");

var xPos = 200;
var yPos = 0;

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;
myObj.style.top =yPos+"px";

function changePos(){
    width = document.documentElement.clientWidth;
    height = document.documentElement.clientHeight;
    
    Hoffset = myObj.offsetHeight;
    Woffset = myObj.offsetWidth;
    
    myObj.style.left = xPos + "px";
    myObj.style.top =document.documentElement.scrollTop+ yPos + "px";
    
    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(){
    myObj.visibility = "visible";
    interval = setInterval('changePos()', delay);
}
start();
myObj.onmouseover = function() {
clearInterval(interval);
interval = null;
}
myObj.onmouseout = function() {
interval = setInterval('changePos()', delay);
}  
</script>

[本日志由 hwarker 于 2012-06-25 03:17 PM 编辑]

引用通告: 查看所有引用 | 我要引用此文章
Tags: 符合W3C声明的漂浮广告代码
收藏到网摘:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.