js实现跟随鼠标移动且带关闭功能的图片广告实例
本文实例讲述了js实现跟随鼠标移动且带关闭功能的图片广告。分享给大家供大家参考。具体实现方法如下:
代码如下:
<!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> <title>跟随鼠标移动且带关闭功能的图片广告</title> <meta http-equiv="content-type" content="text/html;charset=gb2312"> </head> <body> <!--把下面代码加到<body>与</body>之间--> <script type="text/javascript"> //<![CDATA[ function badAD(html){ var ad=document.body.appendChild(document.createElement('div')); ad.style.cssText="border:1px solid #000;background:#FFF;position:absolute;padding:24px 4px 4px 4px;font: 12px/1.5 verdana;"; ad.innerHTML=html||'This is bad idea!'; var c=ad.appendChild(document.createElement('span')); c.innerHTML="×"; c.style.cssText="position:absolute;right:2px;top:2px;cursor:pointer"; c.onclick=function (){ document.onmousemove=null; this.parentNode.style.left='-99999px' }; document.onmousemove=function (e){ e=e||window.event; var x=e.clientX,y=e.clientY; setTimeout(function() { if(ad.hover)return; ad.style.left=x+5+'px'; ad.style.top=y+5+'px'; },120) } ad.onmouseover=function (){ this.hover=true }; ad.onmouseout=function (){ this.hover=false } } badAD('<img src="/images/m02.jpg">') //]]> </script> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
相关推荐
gufudhn 2020-06-06
nercon 2020-06-02
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12