บทความนี้อธิบายโฆษณารูปภาพที่ติดตามเมาส์และปิดฟังก์ชั่น แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <! 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 [
ฟังก์ชั่น badad (html) {
var ad = document.body.appendchild (document.createelement ('div'));
Ad.style.csstext = "Border: 1px Solid #000; ความเป็นมา: #FFF; ตำแหน่ง: Absolute; การตอบสนอง: 24px 4px 4px 4px; แบบอักษร: 12px/1.5 Verdana;";
ad.innerhtml = html || 'นี่เป็นความคิดที่ไม่ดี!';
var c = ad.appendchild (document.createelement ('span'));
c.innerhtml = "×";
C.STYLE.CSSTEXT = "ตำแหน่ง: สัมบูรณ์; ขวา: 2PX; TOP: 2PX; เคอร์เซอร์: ตัวชี้";
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 () {
ถ้า (ad.hover) กลับ;
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 ของทุกคน