JS实现广告窗体效果
2012-10-16 22:02
316 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> .one{ width:200px; height:220px; background-color:#CC3; position:absolute; top=0px; left=0px; } </style> <script> //div1.offsetHeight实际元素的高度 数值一直都是220 不带单位px //div1.offsetLeft 当前元素的位置 window.onload = function(){ var div1= document.getElementsByTagName("div")[0]; var span1= document.getElementsByTagName("div")[0]; var sx=5,sy=5,x,y; var time = setInterval(func,20); function func(){ if(document.documentElement.clientWidth-x<div1.offsetWidth || x<0) { sx = -sx; } if(document.documentElement.clientHeight - y<div1.offsetHeight ||y<0){ sy = -sy; } x = div1.offsetLeft + sx; y = div1.offsetTop + sy; div1.style.left = x +"px"; div1.style.top = y +"px"; // alert(div1.offsetHeight); //alert(div1.offsetLeft); } div1.onmouseover=function(){ clearInterval(time); } div1.onmouseout=function(){ time = setInterval(func,20); } span1.onclick=function(){ document.body.removeChild(div1); div1=null; } } </script> </head> <body> <div class="one"> <span>X</span> </div> </body> </html>
相关文章推荐
- JS实现网页漂浮广告效果简单
- jQuery实现的右下角广告窗体跟随效果示例
- JS使用cookie实现只出现一次的广告代码效果
- js+flash实现的5图变换效果广告代码(附演示与demo源码下载)
- JS实现可关闭的对联广告效果代码
- js网页侧边随页面滚动广告效果实现
- JS平滑无缝滚动实现———实现首页广告自动滚动效果(附实例)
- js实现广告漂浮效果
- js实现随屏幕滚动的带缓冲效果的右下角广告代码
- [JS代码]用JavaScript实现网页轮换广告效果
- js实现广告漂浮效果的小例子
- chrome不兼容position:fixed 对联广告JS 不用JS做对联广告效果 CSS实现对联广告效果
- JS实现可关闭的对联广告效果代码
- js读写cookie实现一个底部广告浮层效果的两种方法
- js+flash实现的5图变换效果广告代码(附演示与demo源码下载)
- chrome不兼容position:fixed 对联广告JS 不用JS做对联广告效果 CSS实现对联广告效果
- 用javascript实现仿163的js广告向下挤压页面的效果
- JS实现自定义弹出窗体,效果不好
- js实现随屏幕滚动的带缓冲效果的右下角广告代码
- js网页侧边随页面滚动广告效果实现