(转)JS浮动窗口(随浏览器滚动而滚动)

2020-11-15 00:23

阅读:610

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

 

窗口中的内容

放在

下面(页面最上面)

  

JS代码

window.onload=function(){

var n=0;//top值

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

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

window.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,当然,,代码可随你自己的意,


评论


亲,登录后才可以留言!