This article describes the image advertisements that follow the mouse and close the function. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<!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>Picture ads that follow the mouse and have off function</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<body>
<!--Add the following code between <body> and </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>
I hope this article will be helpful to everyone's JavaScript programming.