js实现全屏漂浮广告方法三
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>简单JS动画实例 广告移动效果</title>
</head>
<body>
<div id="one" style="background:url(images/1.jpg) no-repeat; position:absolute; left:0; top:0; height:100px; height:100px; ">
移动广告
</div>
<script type="text/javascript">
var x = 0; //对象X轴位置
var y = 0; //对象Y轴位置
var xs = 10; //对象X轴移动速度
var ys = 10; //对象Y轴移动速度
var one = document.getElementById('one');
function move() {
x += xs;
y += ys;
one.style.left = x;
one.style.top = y;
if (x > document.body.clientWidth - one.offsetWidth - 20 || x < 0) {
xs = -1 * xs; //速度取反
}
if (y > document.body.clientHeight - one.offsetHeight - 20 || y < 0) {
ys = -1 * ys;
}
}
var obj = setInterval('move()', 100);
one.onmouseover = function() { //
clearInterval(obj);
}
one.onmouseout = function() {
obj = setInterval('move()', 100);
}
</script>
</body>
</html>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634809.html