var Floater =function (){
this.mydiv = document.createElement("div");
this.delay =25;
this.step = 1;
this.x = 50;
this.y = 60;
this.xin = true;
this.yin = true;
}
Floater.prototype.setElements = function(path,link){
this.mydiv.style.position = "absolute";
var img = document.createElement("img");
img.style.height = 100 +"px";
img.style.width = 100 +"px";
img.src = path ;
var mylink = document.createElement("a");
mylink.href=link ;
mylink.appendChild(img);
this.mydiv.appendChild(mylink);
document.body.appendChild(this.mydiv);
this.start();
}
Floater.prototype.start = function(){
var obj =this;
var itl= setInterval(function(){obj.run(obj);}, obj.delay)
this.mydiv.οnmοuseοver=function(){clearInterval(itl)}
this.mydiv.οnmοuseοut=function(){itl=setInterval(function(){obj.run(obj);}, obj.delay)}
};
Floater.prototype.run = function (obj) {
var L=T=0;
var R= document.body.clientWidth- obj.mydiv.offsetWidth;
var B = document.body.clientHeight - obj.mydiv.offsetHeight;
obj.mydiv.style.left = obj.x + document.body.scrollLeft+'px';
obj.mydiv.style.top = obj.y + document.body.scrollTop+'px';
obj.x = obj.x + obj.step*(obj.xin?1:-1)
if (obj.x < L) { obj.xin = true; obj.x = L}
if (obj.x > R){ obj.xin = false; obj.x = R}
obj.y = obj.y + obj.step*(obj.yin?1:-1)
if (obj.y < T) { obj.yin = true; obj.y = T }
if (obj.y > B) { obj.yin = false; obj.y = B }
}
页面漂浮脚本。第一个面向对象的js
最新推荐文章于 2024-07-14 01:15:24 发布