zoukankan      html  css  js  c++  java
  • js把div固定在页面的右下角

      在公司做材料系统中,需要做一个总是居于右下角的div,但是因为右边这部分本就是用iframe做的,所以是不好弄的。

          一开始,以为用position:fixed,一句css就可以完成,结果在iframe里面这个单页面倒是可以做到,但是一旦有加上模版页面,嵌在iframe中,就不行了。

      所以不断搜索啊,问度娘,看到了这个

          

    <script type="text/javascript">
    window.onscroll= window.onresize = window.onload = function (){
    var getDiv = document.getElementById('rightBottom');
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    
    getDiv.style.left= document.documentElement.clientWidth - getDiv.offsetWidth+'px';
    getDiv.style.top = document.documentElement.clientHeight-getDiv.offsetHeight +scrollTop +'px';
    }
    
    </script>

          但是因为我们是嵌套在iframe中,所以我们找的肯定是夫级页面,所以,代码应该变成如下

    window.parent.onscroll = window.parent.onresize =  window.onload =function () {
      var oFix_box = document.getElementById('select-panel');
      var oscrollTop = window.parent.document.documentElement.scrollTop || window.parent.document.body.scrollTop;
      oFix_box.style.top = oscrollTop + window.parent.document.documentElement.clientHeight - oFix_box.offsetHeight - 224 + 'px';
      $("#select-panel").stop(true,true).animate({ "top": top1 }, 700);
    }
  • 相关阅读:
    为何与0xff进行与运算
    智能指针学习笔记
    linux下多线程编程
    redis源码分析之内存布局
    spring
    java
    程序员进修之路
    散列类型(hash)
    字符串类型
    Jmeter使用Websocket插件测试SingalR,外加还有阿里云PTS的Jmeter原生测试爬坑日志。
  • 原文地址:https://www.cnblogs.com/wanliyuan/p/3737368.html
Copyright © 2011-2022 走看看