[转]浮动窗口

<!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"  xml:lang="zh-CN" lang="zh-CN">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<style>
#floatBox{position:absolute;border:2px solid #ccc;width:100px;height:200px;background:#f5f5f5;}
</style>
<script>
 var curY = 0;
 var offY = 0;
 var abY = 0;
function FloatPosition()
{
 var obj = document.getElementById("floatBox");
 curY = Math.ceil(obj.style.top.replace(/px/,""));
 abY  = Math.ceil(document.documentElement.scrollTop);
 offY = 0.2 * (abY - curY);
 curY += offY;
 obj.style.top = String(curY) + "px";
}
window.setInterval("FloatPosition()",2);
</script>
</head>

<body>
 <div id="floatBox" style='z-index:200;'>
  这是浮动的窗口
  <input type="button" value="固定位置" />
 </div>

</div>

This article is posted by on , link is .

Leave a reply