请教飘浮层或者图片的代码使其在当前屏幕随机飘浮,但不受滚动条控制,
假如页面较长当滚动条下拉时飘浮层或者图片仍然在当前屏幕飘浮

解决方案 »

  1.   

    那就将 scrollTop 加到 浮动层的top 不就可以了吗 
      

  2.   


    下面的JS代码在页面不添加
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    时可实现效果但是增加了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    后总是从指定位置开始飘动,请教如何修改使其使用更标准 规范 //
    //调用页面增加了
    //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    //就不能当前屏幕飘动
    var obj=document.getElementById("ad") 
    var xPos = document.body.clientWidth/2;// 页面本身宽度 起始横向位置(从左算起,单位象素)
      var yPos = document.body.clientHeight;// 页面本身高度
      var step = 1; 
      var delay = 30; // 速度,值越大速度越慢
      var height = 0;
      var Hoffset = 0;
      var Woffset = 0;
      var yon = 0;
      var xon = 0;
      var pause = true;
      var interval;
      obj.style.top = yPos;
      function changePos() {
      width = document.body.clientWidth;// 判断浏览器窗口的宽度
      height = document.body.clientHeight; // 判断浏览器窗口的高度
      Hoffset = obj.offsetHeight;
      Woffset = obj.offsetWidth;
      obj.style.left = xPos + document.body.scrollLeft;
      obj.style.top = yPos + document.body.scrollTop;
      if (yon) {
      yPos = yPos + step;
      }
      else {
      yPos = yPos - step;
      }
      if (yPos < 0) {
      yon = 1;
      yPos = 0;
      }
      if (yPos >= (height - Hoffset)) {
      yon = 0;
      yPos = (height - Hoffset);
      }
      if (xon) {
      xPos = xPos + step;
      }
      else {
      xPos = xPos - step;
      }
      if (xPos < 0) {
      xon = 1;
      xPos = 0;
      }
      if (xPos >= (width - Woffset)) {
      xon = 0;
      xPos = (width - Woffset);
       }
      }
      function start() {
      obj.visibility = "visible";
      interval = setInterval('changePos()', delay);
      }
      function pause_resume() {
      if(pause) {clearInterval(interval);pause = false;}
      else {interval = setInterval('changePos()',delay);pause = true;}
      }
      start();
      

  3.   

    document.body
    -->
    document.documentElement
      

  4.   

    想问下document.body 和document.documentElement的区别
      

  5.   

    GG(document.body 和document.documentElement的区别)http://blog.163.com/ljian_lj/blog/static/6834332200811247166696/