下面的JS文件:
function $(id) ...{
return document.getElementById(id);
}
function scrollBanner(timer, moveNumber) ...{
function move(o) ...{
var st = document.documentElement.scrollTop + o.t;
var sl = document.documentElement.scrollLeft + (o.c == 0 ? o.a : document.documentElement.clIEntWidth - o.a - o.offsetWidth);
var tc = st - o.offsetTop, lc = sl - o.offsetLeft;
with (o.style) ...{
top = o.offsetTop + (tc != 0 ? tc / Math.abs(tc) : 0) * Math.min(Math.abs(tc), moveNumber) + "px";
left = o.offsetLeft + (lc != 0 ? lc / Math.abs(lc) : 0) * Math.min(Math.abs(lc), moveNumber) + "px";
}
if (o.person) ...{
with (o.person.style) ...{
top = o.offsetTop + "px";
left = o.offsetLeft + o.offsetWidth - o.person.offsetWidth + "px";
}
}
}
var hidden = function() ...{
var o = this.parent;
window.clearInterval(o.interval);
o.parentNode.removeChild(o);
this.parentNode.removeChild(this);
}
this.add = function (to, t, a, c, lo) ...{
/**//*
to為object對象
t為距離頂端距離
當c = 0的時候,a為距離左邊的距離
當c != 0的時候,a為距離右邊的距離
lo為關閉按鈕
*/
var div, exec = function () ...{
move(to);
};
to.person = lo;
to.t = t;
to.a = a;
to.c = c;
with (to.style) ...{
position = "absolute";
display = "block";
top = document.documentElement.scrollTop + t;
left = document.documentElement.scrollLeft + (c == 0 ? a : document.documentElement.clIEntWidth - a - to.offsetWidth);
}
("undefined" != typeof lo) ...{
with (lo.style) ...{
position = "absolute";
display = "block";
}
lo.onmousedown = hidden;
lo.parent = to;
}
exec();
to.interval = window.setInterval(exec, timer);
};
}
window.onload = function () ...{
var b = new scrollBanner(10,15);
b.add($("lwc"), 80, 10, 0, $("lwc_c"));
b.add($("rwc"), 80, 10, 1, $("rwc_c"));
b = null;
}
下面是頁面的調用:
<div id="lwc" runat="server"><a href="#" target="_blank"><img src="duilianguanggaowei1.jpg" width="97" height="240" border="0" /></a></div >
<div id="rwc" runat="server"><a href="#" target="_blank"><img src="duilianguanggaowei1.jpg" width="97" height="240" border="0" /></a></div >
<input class="close" id="lwc_c" runat="server" type="text" value="¤關閉" /><input class="close" id="rwc_c" runat="server" type="text" value="¤關閉" />
<asp:Label ID="Label1" runat="server"></ASP:Label>
<ASP:Button ID="Button1" runat="server" Text="不顯示" OnClick="Button1_Click" />
<ASP:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="顯示" />
還有CSS文件:
#lwc, #rwc {...}{
width:97px;
height:240px;
background:#009999;
}
#lwca, #rwca {...}{
width:97px;
height:97px;
background:#009999;
}
.close{...}{
height: 13px;
width: 13px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-repeat: no-repeat;
margin-top: 2px;
margin-right: 2px;
}