JS浮动窗口(随浏览器滚动而滚动)
2010-08-31 09:34

往往用于一些联系方式,互动平台模块,随着浏览器的滚动而滚动。

  

<div >

<p>窗口中的内容</p>

</div>

   

<!--#include file="fly.asp" -->放在<body>下面(页面最上面)

    

JS代码

window.onload=function(){

var n=0; //top

var obj=document.getElementById("AdLayer"); //position:fixed对象

if(document.body.scrollTop)

{

window.onscroll=function(){obj.style.top=(document.body.scrollTop)+n+'px';}

window.onresize=function(){obj.style.top=(document.body.scrollTop)+n+'px';}

 }

else

{  

document.documentElement.onscroll=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}

document.documentElement.onresize=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}

}

}

   

CSS代码:

#AdLayer { background:url(../images/gj_3.jpg) no-repeat top center; 

right:0; top:0; width:80px; height:235px; position:absolute; padding-right:10px; padding-top:75px; text-align:center; margin-top:150px;}

   

CSS代码分析,背景图片,大小宽80,高235,浮动,靠右上,窗口的内容居中,与上的距离为75,窗口跟上的距离为150,当然,,代码可随你自己的意,

阅读全文
类别:默认分类 查看评论

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-06-17
  • 2021-12-26
  • 2021-07-06
  • 2021-10-10
  • 2021-09-18
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2021-07-03
  • 2021-07-07
  • 2022-02-07
  • 2022-12-23
相关资源
相似解决方案