|
<SPAN style="FONT-SIZE: 12px" twffan="done"> 现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,本文介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,下面文本框中就是实现效果所需代码: <BR> var delta=0.015<BR> var collection;<BR> function floaters() {<BR> this.items = [];<BR> this.addItem = function(id,x,y,content)<BR> {<BR> document.write('&lt;DIV id=' id ' style="Z-INDEX: 0; POSITION: absolute; width:80px; height:60px;left:' (typeof(x)=='string'?eval(x):x) ';top:' (typeof(y)=='string'?eval(y):y) '"&gt;' content '&lt;/DIV&gt;');<BR> <BR> var newItem = {};<BR> newItem.object = document.getElementById(id);<BR> newItem.x = x;<BR> newItem.y = y; <BR> this.items[this.items.length] = newItem;<BR> }<BR> this.play = function()<BR> {<BR> collection = this.items<BR> setInterval('play()',10);<BR> }<BR> }<BR> function play()<BR> {<BR> if(screen.width&lt;=800)<BR> {<BR> for(var i=0;i&lt;collection.length;i )<BR> {<BR><EM> </EM> collection.object.style.display = 'none';<BR> }<BR> return;<BR> }<BR> for(var i=0;i&lt;collection.length;i )<BR> {<BR> var followObj = collection.object;<BR> var followObj_x = (typeof(collection.x)=='string'?eval(collection.x):collection.x);<BR> var followObj_y = (typeof(collection.y)=='string'?eval(collection.y):collection.y); <BR> if(followObj.offsetLeft!=(document.body.scrollLeft followObj_x)) {<BR> var dx=(document.body.scrollLeft followObj_x-followObj.offsetLeft)*delta;<BR> dx=(dx&gt;0?1:-1)*Math.ceil(Math.abs(dx));<BR> followObj.style.left=followObj.offsetLeft dx;<BR> } <BR> if(followObj.offsetTop!=(document.body.scrollTop followObj_y)) {<BR> var dy=(document.body.scrollTop followObj_y-followObj.offsetTop)*delta;<BR> dy=(dy&gt;0?1:-1)*Math.ceil(Math.abs(dy));<BR> followObj.style.top=followObj.offsetTop dy;<BR> }<BR> followObj.style.display = '';<BR> }<BR> } <BR> <BR> var theFloaters = new floaters();<BR> theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'&lt;/a&gt;&lt;br&gt;&lt;a href=广告链接地址 target=_blank&gt;&lt;img src=广告图片地址 width=100 height=400 border=0&gt;&lt;/a&gt;');<BR> theFloaters.addItem('followDiv2',0,0,'&lt;br&gt;&lt;a href=广告链接地址 target=_blank&gt;&lt;img src=广告图片地址 width=100 height=400 border=0&gt;&lt;/a&gt;');<BR> theFloaters.play(); <BR>把上面的代码另存为一个JS文件,然后在想实现此效果的页面用&lt;script type="text/java script" language="java script1.2" src="*.js"&gt;&lt;/SCRIPT&gt;调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址! <BR></SPAN> |
|