返回触发onscr......登陆

触发onscroll事件

肖凌2019-05-10 10:46:00276

<!DOCTYPE html>

<html>

         <head>

         <title></title>

         <style type="text/css">

         *{margin:0 0;}

         .my_menu{

         width:100%;

         height:70px;

         background:#ccc;

         line-height:70px;

         text-align:center;

         }

         .my_body{

         width:100%;

         height:1600px;

         background:pink;

         }

         input{

                 border:1px solid #ccc;

                 width:500px;

                 height:30px;

                 border-radius:10px;

                 outline:none;

                 padding:2px 20px;

                 font-size:20px;

                 }

             .fix_menu{

                             width:100%;

                             height:70px;

                             background:#ccc;

                             line-height:70px;

                             text-align:center;

                             position:fixed;

                             display:none;

                             top:0;

                             }


                  </style>

             </head>

         <body>

         <div class="my_menu">

                      <input type="" name="">

         </div>

         <div class="fix_menu">

                      <input type="" name="">

         </div>

                      <div class="my_body">

         </div>

         <script type="text/javascript">

                     window.onload=function(){

                                  var dis_menu=document.getElementsByClassName('fix_menu');

                                    //当滚动栏坐标大于100px时触发事件

                                  window.onscroll=function(){

                                              if(document.documentElement.scrollTop>100){

                                                              dis_menu[0].style.display='block';

                                                          }

                                              else{

                                                         dis_menu[0].style.display='none';

                                                     }

                                        }

                               }

                       </script>

              </body>

    </html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送