JS悬浮窗口如何实现

JavaScript010

JS悬浮窗口如何实现,第1张

jsp中:

<body>

<div style="position: absolutez-index:90" id="div1">我不动</div>

<div>我动<div>

</body>

//有的将position设置成fixed,我试了试效果不如position好,设置z-index,向里的深度,我这儿设置90,你要覆盖几个div,设置数大于那个数就行。

js中:

我这儿用jquery写。

$(document).ready(function(){

$(window).scroll(function(){//滚动时触发函数

$("#div1").css("top",$(document).scrollTop())//将滚动条高度赋给悬浮框。

})

})

导入jquery库,效果就出来了。

body {margin:0 padding:0 10px 0 10pxheight:100%overflow:autobackground:#333font-size:12px}

#wrap {display:blockbottom:0pxright:1px!importantright:18pxwidth:200pxline-height:30pxposition:fixedborder:1px solid #ffftext-align:centercolor:#fff background:#000}

*html{overflow-x:autooverflow-y:auto}

* html #wrap {position:absolute}

上面是样式部分

<div style="height:3986px"></div>

<div id="wrap">我是不会动的,只有这个地方是属于我的,在你没有更改我的位置之前。<br>

<a href="http://www.CsrCode.cn&quot>CsrCode.CN</a>丨<a href="http://www.CsrCode.cn&quot>芯晴网页特效</a>丨<a href="http://www.CsrCode.cn&quot>seo优化</a>

这是HTML部分

开玩笑!你直接复制过去!

页面的其他部分有没有设置定位!有的话删除!

自己看有没有在。看下自己页面其他地方有没设置定位。有的话删了