`
yuxuguang
  • 浏览: 137077 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

网页浮动广告

阅读更多

第一种方式:

<script> 
var Rimifon = { 
"Ads" : new Object, 
"NewFloatAd" : function(imgUrl, strLink) 
{ 
var ad = document.createElement("a"); 
ad.DirV = true; 
ad.DirH = true; 
ad.AutoMove = true; 
ad.Image = new Image; 
ad.Seed = Math.random(); 
ad.Timer = setInterval("Rimifon.Float(" + ad.Seed + ")", 50); 
this.Ads[ad.Seed] = ad; 
ad.Image.Parent = ad; 
ad.style.position = "absolute"; 
ad.style.left = 0; 
ad.style.top = 0; 
ad.Image.src = imgUrl; 
ad.Image.onmouseover = function(){this.Parent.AutoMove = false;} 
ad.Image.onmouseout = function(){this.Parent.AutoMove = true;} 
if(strLink) 
{ 
ad.href = strLink; 
ad.Image.border = 0; 
ad.target = "_blank"; 
} 
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"; 
} 
} 
} 
</script><body><div style="width:30cm;height:40cm"></div></body><script> 
Rimifon.NewFloatAd("http://www.jb51.net/images/logo.gif", "http://www.baidu.com"); 
//var ad = Rimifon.NewFloatAd("http://www.jb51.net/images/logo.gif"); 
//ad.style.left = 500; 
//ad.style.top = 456; 
//ad.Image.width = 88; 
//ad.Image.height = 31; 
</script> 

 

 

 

 

第二种方式:

    方法:直接吧此页面引入即可

<script>
function alertwindow(url)
    {   
        window.open(url);
    }
</script>
<div id="floatAD" style="position:absolute;z-index:10;"> 
<TABLE cellSpacing=0 cellPadding=0  border=0>	
	<TR>		
		<TD><img src="/uploadfiles/ad/image/000.jpg" border="0" width="80" height="80" onclick="alertwindow('http://www.baoying.com')"></TD>
	</TR>
	<TR bgColor=#CCCCCC>
		<TD height="20" align="right"><span style="CURSOR: hand;color:white;font-size:12px;margin-right:4px;" onclick="closefloatAD()">关闭</span></TD>
	</TR>
</TABLE>
</div> 
<script> 
var x = 50,y = 60 
var xin = true, yin = true 
var step = 1 
var delay = 10 
var obj=document.getElementById("floatAD") 
function floatAD() { 
var L=T=0 
var R= document.body.clientWidth-obj.offsetWidth 
var B = document.body.clientHeight-obj.offsetHeight 
obj.style.left = x + document.body.scrollLeft 
obj.style.top = y + document.body.scrollTop 
x = x + step*(xin?1:-1) 
if (x < L) { xin = true; x = L} 
if (x > R){ xin = false; x = R} 
y = y + step*(yin?1:-1) 
if (y < T) { yin = true; y = T } 
if (y > B) { yin = false; y = B } 
} 
var itl= setInterval("floatAD()", delay) 
obj.onmouseover=function(){clearInterval(itl)} 
obj.onmouseout=function(){itl=setInterval("floatAD()", delay)} 
function closefloatAD()
{
	document.getElementById('floatAD').style.visibility='hidden';
	if(itl) window.clearInterval(itl)
}
</script>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics