小弟在以前的帖子中搜到个兼容火狐,W3C的浮动广告,但是不会写鼠标悬停的事件,
那位JS高手能帮我加上段悬停代码啊,谢谢!
就是鼠标放上去让他不滚动,鼠标离开在继续滚动var step = 1;
var speed = 10;
var collection;
function floaters_move(){
this.items = [];
this.addItem = function(id,x,y,content){
document.write('<div id='+id+' style="z-index:2; position:absolute;">'+content+'</div>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.xPos = x;
newItem.yPos = y;
newItem.xon = 0;
newItem.yon = 0;
this.items[this.items.length] = newItem;
}
this.play = function(){
collection = this.items;
setInterval('move_play()',speed);
}
this.delay = function(){
collection = this.items;
setInterval("move_play()", delay);
}
}
function move_play(){
for(var i=0;i <collection.length;i++){
var followObj = collection[i].object;
var followObj_x = followObj.offsetWidth;
var followObj_y = followObj.offsetHeight;
var sLeft=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);
var sTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop);
followObj.style.left = (collection[i].xPos + sLeft)+'px';
followObj.style.top = (collection[i].yPos + sTop)+'px';
if(collection[i].xon) collection[i].xPos += step;
else collection[i].xPos -= step;
if(collection[i].yon) collection[i].yPos += step;
else collection[i].yPos -= step;
if(collection[i].xPos >= (document.documentElement.clientWidth-followObj_x)){
collection[i].xon = 0;
collection[i].xPos = document.documentElement.clientWidth-followObj_x;
}
if(collection[i].xPos < 0){
collection[i].xon = 1;
collection[i].xPos = 0;
}
if(collection[i].yPos >= (document.documentElement.clientHeight-followObj_y)){
collection[i].yon = 0;
collection[i].yPos = document.documentElement.clientHeight-followObj_y;
}
if(collection[i].yPos < 0){
collection[i].yon = 1;
collection[i].yPos = 0;
}
}
}var theFloaters_move = new floaters_move();
theFloaters_move.addItem('myad',0,0,'<a href="http://www.baidu.net/1.html" target=_blank><img src="images/float.jpg" width="250" height="210" border="0" /></a>');
theFloaters_move.play();
那位JS高手能帮我加上段悬停代码啊,谢谢!
就是鼠标放上去让他不滚动,鼠标离开在继续滚动var step = 1;
var speed = 10;
var collection;
function floaters_move(){
this.items = [];
this.addItem = function(id,x,y,content){
document.write('<div id='+id+' style="z-index:2; position:absolute;">'+content+'</div>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.xPos = x;
newItem.yPos = y;
newItem.xon = 0;
newItem.yon = 0;
this.items[this.items.length] = newItem;
}
this.play = function(){
collection = this.items;
setInterval('move_play()',speed);
}
this.delay = function(){
collection = this.items;
setInterval("move_play()", delay);
}
}
function move_play(){
for(var i=0;i <collection.length;i++){
var followObj = collection[i].object;
var followObj_x = followObj.offsetWidth;
var followObj_y = followObj.offsetHeight;
var sLeft=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);
var sTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop);
followObj.style.left = (collection[i].xPos + sLeft)+'px';
followObj.style.top = (collection[i].yPos + sTop)+'px';
if(collection[i].xon) collection[i].xPos += step;
else collection[i].xPos -= step;
if(collection[i].yon) collection[i].yPos += step;
else collection[i].yPos -= step;
if(collection[i].xPos >= (document.documentElement.clientWidth-followObj_x)){
collection[i].xon = 0;
collection[i].xPos = document.documentElement.clientWidth-followObj_x;
}
if(collection[i].xPos < 0){
collection[i].xon = 1;
collection[i].xPos = 0;
}
if(collection[i].yPos >= (document.documentElement.clientHeight-followObj_y)){
collection[i].yon = 0;
collection[i].yPos = document.documentElement.clientHeight-followObj_y;
}
if(collection[i].yPos < 0){
collection[i].yon = 1;
collection[i].yPos = 0;
}
}
}var theFloaters_move = new floaters_move();
theFloaters_move.addItem('myad',0,0,'<a href="http://www.baidu.net/1.html" target=_blank><img src="images/float.jpg" width="250" height="210" border="0" /></a>');
theFloaters_move.play();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货