現在很多網站廣告做的如火如荼現在我就來介紹一下常見的對聯浮動廣告效果的代碼使用方法本文介紹的這種效果在*分辨率下正常顯示在*的分辨率下可以自動隱藏以免遮住頁面影響訪問者浏覽內容而且與前面兩個代碼不同的是廣告圖下方增加了一個圖片按紐允許訪客點擊關閉廣告圖片下面文本框中就是實現效果所需代碼
var delta=;
var collection;
var closeB=false;
function floaters() {
ems = [];
thisaddItem = function(idxycontent)
{
documentwrite(<DIV id=+id+ >+content+</DIV>);
var newItem = {};
newItemobject = documentgetElementById(id);
newItemx = x;
newItemy = y;
ems[emslength] = newItem;
}
thisplay = function()
{
collection = ems
setInterval(play());
}
}
function play()
{
if(screenwidth<= || closeB)
{
for(var i=;i<collectionlength;i++)
{
collection[i]objectstyledisplay = none;
}
return;
}
for(var i=;i<collectionlength;i++)
{
var followObj = collection[i]object;
var followObj_x = (typeof(collection[i]x)==string?eval(collection[i]x):collection[i]x);
var followObj_y = (typeof(collection[i]y)==string?eval(collection[i]y):collection[i]y);
if(followObjoffsetLeft!=(documentbodyscrollLeft+followObj_x)) {
var dx=(documentbodyscrollLeft+followObj_xfollowObjoffsetLeft)*delta;
dx=(dx>?:)*Mathceil(Mathabs(dx));
followObjstyleleft=followObjoffsetLeft+dx;
}
if(followObjoffsetTop!=(documentbodyscrollTop+followObj_y)) {
var dy=(documentbodyscrollTop+followObj_yfollowObjoffsetTop)*delta;
dy=(dy>?:)*Mathceil(Mathabs(dy));
followObjstyletop=followObjoffsetTop+dy;
}
followObjstyledisplay = ;
}
}
function closeBanner()
{
closeB=true;
return;
}
var theFloaters = new floaters();
//
theFloatersaddItem(followDivdocumentbodyclientWidth<a onClick=closeBanner(); href= target=_blank><img src=/img/js_gif width= height= border=></a><br><img src=/img/js_closegif onClick=closeBanner();>);
theFloatersaddItem(followDiv<a onClick=closeBanner(); href= target=_blank><img src=/img/js_gif width= height= border= ></a><br><img src=/img/js_closegif onClick=closeBanner();>);
theFloatersplay();
把上面的代碼另存為一個JS文件然後在想實現此效果的頁面用<script type=text/javascript language=javascript src=*js></SCRIPT>調用即可*代表你另存的文件名!注意修改廣告圖片地址和連接地址!
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25461.html