有一个例子,向各位请教一下,
<style>
#leftright, #topdown#leftright, #topdown{
position:absolute;
left:0;
top:0;
width:1px;
height:1px;
layer-background-color:red;
background-color:red;
z-index:100;
font-size:1px;
}
</style>
<script language="JavaScript">
if (document.all&&!window.print)
{
leftright.style.width=document.body.clientWidth-2;
topdown.style.height=document.body.clientHeight-2;
}
function followmouse(){
leftright.style.pixelTop=document.body.scrollTop+event.clientY+1
topdown.style.pixelLeft=document.body.scrollLeft+event.clientX+1
}
document.onmousemove=followmouse
</script>
<div id="leftright" style="width:expression(document.body.clientWidth-2)"></div>
<div id="topdown" style="height:expression(document.body.clientHeight-2)"></div>
我有这么几个问题想请教一下:1)在最后两行设置width和height用的方法是expression(document.body.clientWidth-2),这是什么方法啊?怎么可以在html代码中运算js的程序。
2)又为何在js中还要再设置一遍width和height? 我试了试,如果取消掉任意一个,好像在IE中都无法运行。有什么原因吗?
if (document.all&&!window.print){
leftright.style.width=document.body.clientWidth-2;
topdown.style.height=document.body.clientHeight-2;
}
3)在followmouse函数中,设置对应的pixelTop和pixelLeft,为何还要加上document.body.scrollTop或document.body.scrollLeft?