jQuery.piao = {
"ads": new Object,
"newFloatAd": function(options) {
var defaultValue = { img: "", link: "", width: "190px", height: "48px" };
var opts = $.extend(defaultValue, options || {});
var ad = document.createElement("span");
ad.id = "adId";
ad.innerHTML += "<div οnclick='guanbu(this)'οnmοuseοver='over()' οnmοuseοut='out(this)' style='position:absolute; right:3px; top:0px;cursor:pointer;'>×</div>";
ad.DirV = true;
ad.DirH = true;
ad.AutoMove = true;
ad.style.cursor = 'pointer';
ad.Image = new Image;
ad.Seed = Math.random();
ad.Timer = setInterval("$.piao.float(" + ad.Seed + ")", 50);
this.ads[ad.Seed] = ad;
ad.Image.Parent = ad;
ad.Image.onclick = function() { window.location.href = opts.link; }
ad.style.position = "absolute";
ad.style.left = 0;
ad.style.top = 0;
ad.Image.src = opts.img;
ad.Image.onmouseover = function() { this.Parent.AutoMove = false; }
ad.Image.onmouseout = function() { this.Parent.AutoMove = true; }
ad.Image.style.width = opts.width;
ad.Image.style.height = opts.height;
ad.appendChild(ad.Image);
document.body.appendChild(ad);
return ad;
},
"float": function(floatId) {
var ad = this.ads[floatId];
if (ad.AutoMove) {
var curLeft = parseInt(ad.style.left);
var curTop = parseInt(ad.style.top);
if (ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1) {
curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth;
ad.DirH = false;
}
if (ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1) {
curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight;
ad.DirV = false;
}
if (curLeft < document.body.scrollLeft) {
curLeft = document.body.scrollLeft;
ad.DirH = true;
}
if (curTop < document.body.scrollTop) {
curTop = document.body.scrollTop;
ad.DirV = true;
}
ad.style.left = curLeft + (ad.DirH ? 1 : -1) + "px";
ad.style.top = curTop + (ad.DirV ? 1 : -1) + "px";
}
}
}
$.piao.newFloatAd({ img: "/Images/1.jpg", link: "http://www.baidu.com" });
老效果,七八年前首页流行的漂浮广告