效果如圖:
實現代碼如下:
<DIV id=ad_dl01 style="Z-INDEX: 1; LEFT: 5px; VISIBILITY: visible; WIDTH: 100px; POSITION: absolute; TOP: 95px">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD align=left>
<A onclick="ad_dl01.style.visibility='hidden'">
<IMG height=16 src="yanglan_01.gif" width=100 border=0></A></TD>
</TR>
<TR>
<TD><A href="http://book.csdn.net/programmer/" target=_blank><IMG height=184 src="cxy.gif" width=100 border=0></A></TD></TR></TBODY></TABLE></DIV>
<DIV id=ad_dl02 style="Z-INDEX: 1; RIGHT: 5px; VISIBILITY: visible; WIDTH: 100px; POSITION: absolute; TOP: 95px">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD align=right><A onclick="ad_dl02.style.visibility='hidden'"><IMG height=16 src="yanglan_01.gif" width=100 border=0></A></TD></TR>
<TR>
<TD><A href="http://book.csdn.net/subject/0710asp/" target=_blank><IMG height=184 src="0710aspban100.jpg" width=100 border=0></A></TD></TR></TBODY></TABLE></DIV>
<SCRIPT type=text/javascript>
var step_ratio = 0.1;
objs = new Array();
objs_x = new Array();
objs_y = new Array();
function addfollowmark(name, x, y) {
i = objs.length;
objs[i] = document.getElementById(name);
objs_x[i] = x;
objs_y[i] = y;
}
function followmark() {
for(var i=0; i<objs.length; i++) {
var fm = objs[i];
var fm_x = typeof(objs_x[i]) == 'string' ? eval(objs_x[i]) : objs_x[i];
var fm_y = typeof(objs_y[i]) == 'string' ? eval(objs_y[i]) : objs_y[i];
if (fm.offsetLeft != document.body.scrollLeft + fm_x) {
var dx = (document.body.scrollLeft + fm_x - fm.offsetLeft) * step_ratio;
dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));
fm.style.left = fm.offsetLeft + dx;
}
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop;
if (fm.offsetTop != diffY + fm_y) {
var dy = (diffY + fm_y - fm.offsetTop) * step_ratio;
dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
fm.style.top = fm.offsetTop + dy;
}
fm.style.display = '';
}
}
addfollowmark("ad_dl01", 5, 100);
addfollowmark("ad_dl02", "document.body.clientWidth-105", 100);
setInterval('followmark()',20);
</SCRIPT>
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD align=left>
<A onclick="ad_dl01.style.visibility='hidden'">
<IMG height=16 src="yanglan_01.gif" width=100 border=0></A></TD>
</TR>
<TR>
<TD><A href="http://book.csdn.net/programmer/" target=_blank><IMG height=184 src="cxy.gif" width=100 border=0></A></TD></TR></TBODY></TABLE></DIV>
<DIV id=ad_dl02 style="Z-INDEX: 1; RIGHT: 5px; VISIBILITY: visible; WIDTH: 100px; POSITION: absolute; TOP: 95px">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD align=right><A onclick="ad_dl02.style.visibility='hidden'"><IMG height=16 src="yanglan_01.gif" width=100 border=0></A></TD></TR>
<TR>
<TD><A href="http://book.csdn.net/subject/0710asp/" target=_blank><IMG height=184 src="0710aspban100.jpg" width=100 border=0></A></TD></TR></TBODY></TABLE></DIV>
<SCRIPT type=text/javascript>
var step_ratio = 0.1;
objs = new Array();
objs_x = new Array();
objs_y = new Array();
function addfollowmark(name, x, y) {
i = objs.length;
objs[i] = document.getElementById(name);
objs_x[i] = x;
objs_y[i] = y;
}
function followmark() {
for(var i=0; i<objs.length; i++) {
var fm = objs[i];
var fm_x = typeof(objs_x[i]) == 'string' ? eval(objs_x[i]) : objs_x[i];
var fm_y = typeof(objs_y[i]) == 'string' ? eval(objs_y[i]) : objs_y[i];
if (fm.offsetLeft != document.body.scrollLeft + fm_x) {
var dx = (document.body.scrollLeft + fm_x - fm.offsetLeft) * step_ratio;
dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));
fm.style.left = fm.offsetLeft + dx;
}
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop;
if (fm.offsetTop != diffY + fm_y) {
var dy = (diffY + fm_y - fm.offsetTop) * step_ratio;
dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
fm.style.top = fm.offsetTop + dy;
}
fm.style.display = '';
}
}
addfollowmark("ad_dl01", 5, 100);
addfollowmark("ad_dl02", "document.body.clientWidth-105", 100);
setInterval('followmark()',20);
</SCRIPT>