js/duilian.js
在该文件中添中如下代码:
window.setInterval("heartBeat()",1); //每1秒钟重新定位
suspendcode="<DIV id=lovexin1 style='Z-INDEX: 10; LEFT: 6px; POSITION: absolute; TOP: 105px; width: 110; height: 280px;'><img src='/images/close.gif' onClick='javascript:window.hide()' width='100' height='14' border='0' vspace='3' alt='关闭对联广告'><a href='http://www.ahgxjy.com'
target='_blank'><img src='/images/hf_01.jpg' width='115' height='380' border='0'></a></DIV>"
document.write(suspendcode);
suspendcode="<DIV id=lovexin2 style='Z-INDEX: 10; RIGHT: 6px; POSITION: absolute; TOP: 105px; width: 110; height: 280px;'><img src='/images/close.gif' onClick='javascript:window.hide()' width='100' height='14' border='0' vspace='3' alt='关闭对联广告'><a href='http://www.ahgxjy.com'
target='_blank'><img src='/images/hf_02.jpg' width='115' height='380' border='0'></a></DIV>"
document.write(suspendcode);
//flash格式调用方法
//<EMBED src='flash.swf' quality=high WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=ad wmode=opaque></EMBED>
lastScrollY=0;
function heartBeat(){
diffY=document.body.scrollTop;
percent=.3*(diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.all.lovexin1.style.pixelTop+=percent;
document.all.lovexin2.style.pixelTop+=percent;
lastScrollY=lastScrollY+percent;
}
function hide()
{
lovexin1.style.visibility="hidden";
lovexin2.style.visibility="hidden";
}
window.setInterval("heartBeat()",1);
本文介绍了一种使用JavaScript实现的对联广告浮动效果的方法。通过设置定时器,使页面两侧的广告随滚动条平滑移动,并提供关闭功能。代码简单易懂,适合初学者学习。

159

被折叠的 条评论
为什么被折叠?



