この記事では、マウスに続き、関数を閉じる画像広告について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
次のようにコードをコピーします。
<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 || 'これは悪い考えです!';
var c = ad.appendChild(document.createElement( 'span'));
c.innerhtml = "×";
c.style.csstext = "position:aspolute; 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;
setimeout(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プログラミングに役立つことを願っています。