var o={ adLeftSrc : "", adRightSrc:"", adLeftFlash:"", adLeftHref:"", adLeftWidth:194, adLeftHeight:339, adRightFlash:"", adRightHref:"", adRightWidth:194, adRightHeight:339, marginTop:85, marginLeft:3, navUserAgent:navigator.userAgent } $.extend({ //关闭对联 unloadAd:function (){ $("#adRightFloat,#adLeftFloat").css({visibility:'hidden'}); },//对联随滚动条下滑 moveAd:function () { this.judgeAd(); setTimeout("$.moveAd();",80); }, judgeAd:function (){ if (o.navUserAgent.indexOf("Firefox") >= 0 ||o.navUserAgent.indexOf("Opera") >= 0) { if (o.adLeftSrc != ""){ $("#adLeftFloat").css({top:(document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - o.adLeftHeight - o.marginTop + 'px'});} if (o.adRightSrc != ""){ $("#adRightFloat").css({top:(document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + ((document.body.clientHeight > document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight) - o.adRightHeight - o.marginTop + 'px',left:((document.body.clientWidth > document.documentElement.clientWidth)?document.body.clientWidth:document.documentElement.clientWidth) - o.adRightWidth - o.marginLeft + 'px'}); } } else{ if (o.adLeftSrc != "") {$("#adLeftFloat").css({top:(document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + (document.documentElement.clientHeight == 0?document.body.clientHeight:document.documentElement.clientHeight) - o.adLeftHeight - o.marginTop + 'px'});} if (o.adRightSrc != "") { $("#adRightFloat").css({top:(document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) + (document.documentElement.clientHeight==0?document.body.clientHeight:document.documentElement.clientHeight) - o.adRightHeight - o.marginTop + 'px',left:(document.documentElement.clientWidth == 0?document.body.clientWidth:document.documentElement.clientWidth-o.adRightWidth-o.marginLeft) + 'px'}); } } if(o.adLeftSrc != ""){$("#adLeftFloat").css({left:o.marginLeft + 'px'});} },//页面两侧弹出对联 loadAd : function(options){ var defaults={ leftSrc:"", rightSrc:"", leftFlash:"", leftHref:"", leftWidth:0, leftHeight:0, rightFlash:"", rightHref:"", rightWidth:0, rightHeight:0, marginTop:0, marginLeft:0 }; var opts = $.extend(defaults, options); o.adLeftSrc=opts.leftSrc; o.adRightSrc=opts.rightSrc; o.adLeftFlash=opts.leftFlash; o.adLeftHref=opts.leftHref; o.adLeftWidth=opts.leftWidth; o.adLeftHeight=opts.leftHeight; o.adRightFlash=opts.rightFlash; o.adRightHref=opts.rightHref; o.adRightWidth=opts.rightWidth; o.adRightHeight=opts.rightHeight; o.marginTop=opts.marginTop; o.marginLeft=opts.marginLeft; if(o.adLeftSrc != ""){ if (o.adLeftFlash == "flash") { document.write("<div id=\"adLeftFloat\" style=\"position: absolute;width:" + o.adLeftWidth + ";\"><a href=\"" +o.adLeftHref +"\"><embed src=\"" + o.adLeftSrc + "\" quality=\"high\" width=\"" + o.adLeftWidth + "\" height=\"" + o.adLeftHeight + "\" type=\"application/x-shockwave-flash\"></embed></a></div>"); } else{ document.write("<div id=\"adLeftFloat\" style=\"position: absolute;width:" + o.adLeftWidth + ";\"><a href=\"" + o.adLeftHref +"\"><img src=\"" + o.adLeftSrc + "\" width=\"" + o.adLeftWidth + "\" height=\"" + o.adLeftHeight + "\" border=\"0\" \></a><a href=# onclick=\"$.unloadAd(); \">关闭</a></div>"); } } if(o.adRightSrc != ""){ if (o.adRightFlash == "flash") { document.write("<div id=\"adRightFloat\" style=\"position: absolute;width:" + o.adRightWidth + ";\"><a href=\"" + o.adRightHref +"\"><embed src=\"" + o.adRightSrc + "\" quality=\"high\" width=\"" +o.adRightWidth + "\" height=\"" +o.adRightHeight + "\" type=\"application/x-shockwave-flash\"></a></embed></div>"); } else{ document.write("<div id=\"adRightFloat\" style=\"position: absolute;width:" + o.adRightWidth + ";\"><a href=\"" + o.adRightHref +"\"><img src=\"" + o.adRightSrc + "\" width=\"" + o.adRightWidth + "\" height=\"" + o.adRightHeight + "\" border=\"0\" \></a><a href=# onclick=\"$.unloadAd(); \">关闭</a></div>"); } } this.moveAd(); } });
对联Js代码调用如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script language="JavaScript" type="text/javascript" src="jquery-1.6.js"></script> <script language="JavaScript" type="text/javascript" src="jQPI_008.js"></script> </head> <body> <div style="height:2000px; width:100%; background-color:#999999"></div> <script> $.loadAd({ leftWidth:194, leftHeight:339, rightWidth:194, rightHeight:339, marginTop:85, marginLeft:3, leftSrc:"y2.jpg", rightSrc:"y1.jpg" }); </script> </body> </html>