本文实例讲述了JavaScript中添加随滚动条滚动窗体的方法。分享给大家供大家参考,具体如下:

两种实现方式:

第一种:

<script type=/"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=/"90%/";
 setTimeout(/"scrollImg()/",100);
}
</script>
<div id=/"ad/" style=/"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=/"text/javascript/">
scrollImg();
</script>

第二种:

<html>
<head>
 <meta http-equiv=/"Content-Type/" content=/"text/html; charset=gb2312/">
 <title>Drag and Drop example</title>
 <script language=/"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=/"none/";
return true; 
}
var online= new Array();
 </script>
</head>
<body>
 <div id=/"divStay/" style=/"position: absolute/">
 <table cellspacing=/"0/" cellpadding=/"0/" width=/"100%/" border=/"0/">
  <tbody>
  <tr>
   <td valign=/"top/" width=/"7%/">
   </td>
  </tr>
  </tbody>
 </table>
 </div>
 <div id=/"divStayTopleft/" style=/"position: absolute/">
 <table cellspacing=/"0/" cellpadding=/"0/" width=/"109/" border=/"0/">
  <tr>
  <td colspan=/"3/">
   <a onclick=/"CloseQQ()/" href=/"javascript:;/" shape=/"circle/" coords=/"91,16,12/">
   <img height=/"34/" src=/"images/qq_top.gif/" width=/"109/" usemap=/"#Map/"
    border=/"0/"></a></td>
  </tr>
  <tr>
  <td width=/"6/">
   <img height=/"100/" src=/"images/qq_life.gif/" width=/"6/"></td>
  <td valign=/"top/" width=/"96/" background=/"sto/qq_bg.gif/">
   <table cellspacing=/"0/" cellpadding=/"0/" width=/"90/" align=/"center/" border=/"0/">
   <tr>
    <td height=/"30/">
    <table cellspacing=/"0/" cellpadding=/"0/" width=/"90/" border=/"0/">
     <tr>
     <td>
      <img height=/"13/" src=/"images/qq_ico1.gif/" width=/"16/"><span
      class=/"font_12/"> <span style=/"font-size: 9pt/">客户服务</span></span></td>
     </tr>
    </table>
    </td>
   </tr>
   <tr>
    <td>
    <table border=/"0/" width=/"100%/" cellpadding=/"2/" id=/"table47/">
     <tr>
     <td width=/"15/" valign=/"top/" height=/"23/">
      <img border=/"0/" src=/"images/qq_v01.gif/" width=/"16/" height=/"16/"></td>
     <td valign=/"bottom/">
      <script>document.write(/"<a target=blank href=tencent://message/");</script>
     </td>
     </tr>
    </table>
    </td>
   </tr>
   <tr>
    <td>
    </td>
   </tr>
   <tr>
    <td>
    <table border=/"0/" width=/"100%/" cellpadding=/"2/" id=/"table1/">
     <tr>
     <td width=/"15/" valign=/"top/" height=/"23/">
      <img border=/"0/" src=/"images/qq_n01.gif/" width=/"16/" height=/"16/"></td>
     <td valign=/"bottom/">
      <script>document.write(/"<a target=blank href=tencent://message/");</script>
     </td>
     </tr>
    </table>
    </td>
   </tr>
   <tr>
    <td>
    </td>
   </tr>
   </table>
  </td>
  <td width=/"7/">
   <img height=/"100/" src=/"images/qq_right.gif/" width=/"7/"></td>
  </tr>
  <tr>
  <td colspan=/"3/">
   <img height=/"30/" src=/"images/qq_bottom1.gif/" width=/"109/"></td>
  </tr>
  <tr>
  <td colspan=/"3/">
   <img height=/"33/" src=/"images/qq_logo.gif/" width=/"109/"></td>
  </tr>
 </table>
 </div>
 <script type=/"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"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>

更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript查找算法技巧总结》、《JavaScript动画特效与技巧汇总》、《JavaScript错误与调试技巧总结》、《JavaScript数据结构与算法技巧总结》、《JavaScript遍历算法与技巧总结》及《JavaScript数学运算用法总结》

希望本文所述对大家JavaScript程序设计有所帮助。

标签:
JavaScript,滚动条,滚动窗体

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
评论“JavaScript添加随滚动条滚动窗体的方法”
暂无“JavaScript添加随滚动条滚动窗体的方法”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。