当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js实现全屏漂浮广告移入光标停止移动

js实现全屏漂浮广告移入光标停止移动

2019年07月19日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:<!doctype html><html><head><meta http-equiv="content-ty


<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>js全屏漂浮广告</title>
<style type="text/css">
div#roll{width:100px;height:100px; background-color:#000; color:#fff; position:absolute;}
</style>
</head>

<body>
<div>
<div><h2>js全屏漂浮广告,移入光标停止移动·柯乐义</h2></div>
</div>
<div id="roll">我是广告<br />www.jb51.com</div>
<script type="text/javascript">
var ggroll = {
roll: document.getelementbyid("roll"),
speed: 20,
statusx: 1,
statusy: 1,
x: 100,
y: 300,
winw: document.documentelement.clientwidth - document.getelementbyid("roll").offsetwidth,
winh: document.documentelement.clientheight - document.getelementbyid("roll").offsetheight,
go: function () {
this.roll.style.left = this.x + 'px';
this.roll.style.top = this.y + 'px';

this.x = this.x + (this.statusx ? -1 : 1)
if (this.x < 0) { this.statusx = 0 }
if (this.x > this.winw) { this.statusx = 1 }

this.y = this.y + (this.statusy ? -1 : 1)
if (this.y < 0) { this.statusy = 0 }
if (this.y > this.winh) { this.statusy = 1 }
}
}
var interval = setinterval("ggroll.go()", ggroll.speed);
ggroll.roll.onmouseover = function () { clearinterval(interval) };
ggroll.roll.onmouseout = function () { interval = setinterval("ggroll.go()", ggroll.speed) };
</script>
</body>
</html>

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网