首页 > 编程 > JavaScript > 正文

JS 实现Div向上浮动的实现代码

2019-11-20 23:15:12
字体:
来源:转载
供稿:网友
Html 及 JS 代码如下:
复制代码 代码如下:

<div id="newsOne" onmouseover="CleartTimeInterVal();" onmouseout="resetInterVal();"
style="position: absolute; width: 100px;">
<a href="//www.VeVB.COm" target="_blank">武林网</a>
</div>
<script type='text/javascript'>
var newsOne = document.getElementById("newsOne");
newsOne.style.bottom = 0;
newsOne.style.left = window.screen.availWidth - 100;
var bottom = 0;
function newsScroll() {
if (bottom > (window.screen.availHeight - window.screenTop)) {
bottom = 0;
newsOne.style.bottom = 0;
}
else {
bottom = bottom + 15;
newsOne.style.bottom = bottom;
}
}
var timeid = setInterval(newsScroll, 300);
function CleartTimeInterVal() {
clearInterval(timeid);
}
function resetInterVal() {
timeid = setInterval(newsScroll, 300);
}
</script>

在线运行:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表