窗口悬浮在页面某侧的js代码

JavaScript013

窗口悬浮在页面某侧的js代码,第1张

<html>

<head>

<title>悬浮窗口示例</title>

<scripttype="text/javascript">

window.onscroll=function(){

vardiv=document.getElementById("divSuspended")

div.style.top=document.body.scrollTop

}

window.onresize=window.onscroll

functioninit(){

vardf=document.createDocumentFragment()

for(vari=0i<20i++){

varp=document.createElement("p")

p.appendChild(document.createTextNode("Line"+i))

df.appendChild(p)

}

document.body.appendChild(df)

window.onscroll()

}

</script>

</head>

<bodyonload="init()">

<p>Tryscrollingthiswindow.</p>

<divid="divSuspended"style="position:absolutebuttom:0pxright:0pxcolor:#ccccccwidth:150pxheight:30pxbackground-color:navy">这是悬浮窗口</div>

</body>

</html>

关闭功能么?应该是图片一类的吧。

<script>

function

clo()

{

var

div=document.getElementById("div层的Id")

div.style.display="none"

}

<script>

只需要在图片或者按钮上面添加onClick事件就行了。比如:

<input

type="button"

onClick="clo()">

注意display的属性值none一定要用双引号引起来

不然会报错

抱歉,没注意。如果不想调用js也可以这样写

<input

type="button"

onClick="document.getElementById('div层的ID').style.display='none'">