JavaScript添加随滚动条滚动窗体的方法

两种实现方式:

第一种:

<script type=https://www.jb51.net/"text/javascript/"> function scrollImg(){ var posX,posY; if (window.innerHeight) { posX = window.pageXOffset; posY = window.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop) { posX = document.documentElement.scrollLeft; posY = document.documentElement.scrollTop; } else if (document.body) { posX = document.body.scrollLeft; posY = document.body.scrollTop; } var ad=document.getElementById(/"ad/"); ad.style.top=(posY+500)+/"px/"; // ad.style.left=(posX+500)+/"px/"; ad.style.left=https://www.jb51.net/"90%/"; setTimeout(/"scrollImg()/",100); } </script> <div id=https://www.jb51.net/"ad/" style=https://www.jb51.net/"position:absolute;background:#606060;width:100px;height:100px;border:1px dotted #000;line-height:100px;text-align:center; left: 103px; top: 911px;/">此广告位招租</div> <script type=https://www.jb51.net/"text/javascript/"> scrollImg(); </script>

第二种:

<html> <head> <meta http-equiv=https://www.jb51.net/"Content-Type/" content=https://www.jb51.net/"text/html; charset=gb2312/"> <title>Drag and Drop example</title> <script language=https://www.jb51.net/"javascript/"> function picsize(obj,MaxWidth){ img=new Image(); img.src=obj.src; if (img.width>MaxWidth) { return MaxWidth; } else { return img.width; } } function CloseQQ() { divStayTopleft.style.display=https://www.jb51.net/"none/"; return true; } var online= new Array(); </script> </head> <body> <div id=https://www.jb51.net/"divStay/" style=https://www.jb51.net/"position: absolute/"> <table cellspacing=https://www.jb51.net/"0/" cellpadding=https://www.jb51.net/"0/" width=https://www.jb51.net/"100%/" border=https://www.jb51.net/"0/"> <tbody> <tr> <td valign=https://www.jb51.net/"top/" width=https://www.jb51.net/"7%/"> </td> </tr> </tbody> </table> </div> <div id=https://www.jb51.net/"divStayTopleft/" style=https://www.jb51.net/"position: absolute/"> <table cellspacing=https://www.jb51.net/"0/" cellpadding=https://www.jb51.net/"0/" width=https://www.jb51.net/"109/" border=https://www.jb51.net/"0/"> <tr> <td colspan=https://www.jb51.net/"3/"> <a onclick=https://www.jb51.net/"CloseQQ()/" href=https://www.jb51.net/"javascript:;/" shape=https://www.jb51.net/"circle/" coords=https://www.jb51.net/"91,16,12/"> <img height=https://www.jb51.net/"34/" src=https://www.jb51.net/"images/qq_top.gif/" width=https://www.jb51.net/"109/" usemap=https://www.jb51.net/"#Map/" border=https://www.jb51.net/"0/"></a></td> </tr> <tr> <td width=https://www.jb51.net/"6/"> <img height=https://www.jb51.net/"100/" src=https://www.jb51.net/"images/qq_life.gif/" width=https://www.jb51.net/"6/"></td> <td valign=https://www.jb51.net/"top/" width=https://www.jb51.net/"96/" background=https://www.jb51.net/"sto/qq_bg.gif/"> <table cellspacing=https://www.jb51.net/"0/" cellpadding=https://www.jb51.net/"0/" width=https://www.jb51.net/"90/" align=https://www.jb51.net/"center/" border=https://www.jb51.net/"0/"> <tr> <td height=https://www.jb51.net/"30/"> <table cellspacing=https://www.jb51.net/"0/" cellpadding=https://www.jb51.net/"0/" width=https://www.jb51.net/"90/" border=https://www.jb51.net/"0/"> <tr> <td> <img height=https://www.jb51.net/"13/" src=https://www.jb51.net/"images/qq_ico1.gif/" width=https://www.jb51.net/"16/"><span class=https://www.jb51.net/"font_12/"> <span style=https://www.jb51.net/"font-size: 9pt/">客户服务</span></span></td> </tr> </table> </td> </tr> <tr> <td> <table border=https://www.jb51.net/"0/" width=https://www.jb51.net/"100%/" cellpadding=https://www.jb51.net/"2/" id=https://www.jb51.net/"table47/"> <tr> <td width=https://www.jb51.net/"15/" valign=https://www.jb51.net/"top/" height=https://www.jb51.net/"23/"> <img border=https://www.jb51.net/"0/" src=https://www.jb51.net/"images/qq_v01.gif/" width=https://www.jb51.net/"16/" height=https://www.jb51.net/"16/"></td> <td valign=https://www.jb51.net/"bottom/"> <script>document.write(/"<a target=blank href=tencent://message/?uin=178010108&Site=脚本之家&Menu=yes><img border=0 SRC=http://wpa.qq.com/pa?p=1:615050000:10 alt=[脚本之家]></a>/");</script> </td> </tr> </table> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <table border=https://www.jb51.net/"0/" width=https://www.jb51.net/"100%/" cellpadding=https://www.jb51.net/"2/" id=https://www.jb51.net/"table1/"> <tr> <td width=https://www.jb51.net/"15/" valign=https://www.jb51.net/"top/" height=https://www.jb51.net/"23/"> <img border=https://www.jb51.net/"0/" src=https://www.jb51.net/"images/qq_n01.gif/" width=https://www.jb51.net/"16/" height=https://www.jb51.net/"16/"></td> <td valign=https://www.jb51.net/"bottom/"> <script>document.write(/"<a target=blank href=tencent://message/?uin=251922268&Site=网页特效&Menu=yes><img border=0 SRC=http://wpa.qq.com/pa?p=1:43486831:10 alt=[QQQQQ]></a>/");</script> </td> </tr> </table> </td> </tr> <tr> <td> </td> </tr> </table> </td> <td width=https://www.jb51.net/"7/"> <img height=https://www.jb51.net/"100/" src=https://www.jb51.net/"images/qq_right.gif/" width=https://www.jb51.net/"7/"></td> </tr> <tr> <td colspan=https://www.jb51.net/"3/"> <img height=https://www.jb51.net/"30/" src=https://www.jb51.net/"images/qq_bottom1.gif/" width=https://www.jb51.net/"109/"></td> </tr> <tr> <td colspan=https://www.jb51.net/"3/"> <img height=https://www.jb51.net/"33/" src=https://www.jb51.net/"images/qq_logo.gif/" width=https://www.jb51.net/"109/"></td> </tr> </table> </div> <script type=https://www.jb51.net/"text/javascript/"> function FloatTop() { var startX1 =document.body.offsetWidth-125 ,startY1 = 5; var startX2 =0,startY2 = 95; var ns = (navigator.appName.indexOf(/"Netscape/") != -1); var d = document; function ml(id,startX,startY) { var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id]; if(d.layers)el.style=el; el.sP=function(x,y){this.style.left=x;this.style.top=y;}; el.x = startX; el.y = startY; return el; } window.stayTopLeft=function() { var pY = ns ? pageYOffset : document.body.scrollTop; ftlObj.y += (pY + startY1 - ftlObj.y)/8; ftlObj1.y += (pY + startY2 - ftlObj1.y)/8; ftlObj.sP(document.body.scrollLeft+document.body.offsetWidth-125, ftlObj.y); ftlObj1.sP(ftlObj1.x, ftlObj1.y); setTimeout(/"stayTopLeft()/", 30); } // ftlObj = ml(/"divStay/",document.body.scrollLeft+document.body.offsetWidth-125,0); // ftlObj1 = ml(/"divStayTopLeft/",0,30); ftlObj = ml(/"divStay/",(document.body.scrollLeft+document.body.offsetWidth)/2+379,0); ftlObj1 = ml(/"divStayTopLeft/",(document.body.scrollLeft+document.body.offsetWidth)/2+379,30); stayTopLeft(); } FloatTop(); </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgypyp.html