zoukankan      html  css  js  c++  java
  • html 滚动固定显示js脚本

    <script type="text/javascript">
    function htmlScroll()
    {
    var top = document.body.scrollTop || document.documentElement.scrollTop;
    if(elFix.data_top < top)
    {
    elFix.style.position = 'fixed';
    elFix.style.top = 0;
    elFix.style.left = elFix.data_left;
    }
    else
    {
    elFix.style.position = 'static';
    }
    }

    function htmlPosition(obj)
    {
    var o = obj;
    var t = o.offsetTop;
    var l = o.offsetLeft;
    while(o = o.offsetParent)
    {
    t += o.offsetTop;
    l += o.offsetLeft;
    }
    obj.data_top = t;
    obj.data_left = l;
    }

    var oldHtmlWidth = document.documentElement.offsetWidth;
    window.onresize = function(){
    var newHtmlWidth = document.documentElement.offsetWidth;
    if(oldHtmlWidth == newHtmlWidth)
    {
    return;
    }
    oldHtmlWidth = newHtmlWidth;
    elFix.style.position = 'static';
    htmlPosition(elFix);
    htmlScroll();
    }
    window.onscroll = htmlScroll;

    var elFix = document.getElementById('div1');
    htmlPosition(elFix);

    </script>

    以上就是固定显示的一下记录

  • 相关阅读:
    tp 30秒超时
    zend studio git 提示错误
    php连接数据库
    php点击排序
    表情符号解析
    js Object.assign 方法
    Web界面简繁体转换
    H5骨架屏实战
    JavaScript heap out of memory问题
    Vue bus插件封装
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/3666674.html
Copyright © 2011-2022 走看看