W3C标准漂浮代码鼠标上浮自动停止
作者:hwarker 日期:2012-06-25
符合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>
<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>
评论: 0 | 引用: 0 | 查看次数: -
发表评论