javascript控制DIV显示

<script>
function getPosition() {
      var top    = document.documentElement.scrollTop;
      var left   = document.documentElement.scrollLeft;
      var height = document.documentElement.clientHeight;
      var width  = document.documentElement.clientWidth;
      return {top:top,left:left,height:height,width:width};
}

function showPop(){
 var width  = 300;  //弹出框的宽度
 var height = 160;  //弹出框的高度
 var obj    = document.getElementById("div_pop");
 
 obj.style.display  = "block";
 obj.style.position = "absolute";
 obj.style.zindex   = "999";
 obj.style.width    = width + "px";
 obj.style.height   = height + "px";
 
 var Position = getPosition();
 leftadd = (Position.width-width)/2;
 topadd  = (Position.height-height)/2;
 obj.style.top  = (Position.top  + topadd)  + "px";
 obj.style.left = (Position.left + leftadd) + "px";
 
 //滚动条移动时候改变DIV位置
 window.onscroll = function (){
  var Position   = getPosition();
  obj.style.top  = (Position.top  + topadd)  +"px";
  obj.style.left = (Position.left + leftadd) +"px";
 };
}

function hidePop(){
 document.getElementById("div_pop").style.display = "none";
}
</script> 

阅读更多
文章标签: div javascript function
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

javascript控制DIV显示

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭