提示:您可以先修改部分代碼再運行
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>相容各種瀏覽器的“返回頂部”懸浮效果</title><meta http-equiv="content-type" content="text/html;charset=gb2312"><!--把下面代碼加到<head>與</head>之間--><style type="text/css">*{margin:0;padding:0;}html{_overflow:hidden;}body{_overflow:auto;height:100%;}a{text-decoration:none;}#div{background:#ccc;width:400px;height:1500px;text-align:center;}#returntop{border:1px #ccc solid;background:#F30;width:80px;height:30px;position:fixed;_position:absolute;line-height:30px;text-align:center;top:0px;left:0px;display:none;cursor:pointer;}</style></head><body><!--把下面代碼加到<body>與</body>之間--><div id="div">這是頂部</div><div id="returntop">返回頂部</div><script type="text/javascript">var getDiv=document.getElementById('returntop');var n=0;function scrollEvent(){var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;if(scrollTop){getDiv.style.display="block";}else{getDiv.style.display="none";}n=1;}window.onscroll=scrollEvent;if(n==0){document.body.onscroll=scrollEvent;}function getWinSize(){var winHeight=window.innerHeight,winWidth=window.innerWidth;if(document.documentElement.clientHeight){winHeight=document.documentElement.clientHeight;winWidth=document.documentElement.clientWidth;}else{winHeight=document.body.clientHeight;winWidth=document.body.clientWidth;} var height=winHeight-50;var width=winWidth-100;getDiv.style.top=height+"px";getDiv.style.left=width+"px";}getWinSize();window.onresize=getWinSize;</script></body></html></td> </tr></table>
提示:您可以先修改部分代碼再運行