zoukankan      html  css  js  c++  java
  • js滚动条固定

    <!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">
    <head>
    <style type="text/css">
    *{margin:0px auto; padding:0px;}
    #shang{width:100%; height:200px; background-color:#CF6;}
    #caidan{width:100%; height:100px; background-color:#9C0;}
    .xuanxiang{width:200px; height:100px; background-color:#606; margin-top:20px;}
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <div id="shang"></div>
    <div id="caidan"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    <div class="xuanxiang"></div>
    </body>
    <script type="text/javascript">
    window.onscroll = function(){
                var m = document.getElementById("caidan");
        if(window.scrollY>=200){
            m.style.position="fixed";
            m.style.shang="0px";
            }else{
                m.style.position="";
                }
        }
    </script>
    
    </html>

  • 相关阅读:
    第61课 智能指针类模板
    第60课 数组类模板
    第59课 类模板深度剖析
    第58课 类模板的概念和意义
    第57课 深入理解函数模板
    第56课 函数模板的概念和意义
    第55课 经典问题解析(四)
    155. Min Stack
    141. Linked List Cycle
    136. Single Number
  • 原文地址:https://www.cnblogs.com/palpitate/p/8891246.html
Copyright © 2011-2022 走看看