<i id='PhnaB'><tr id='PhnaB'><dt id='PhnaB'><q id='PhnaB'><span id='PhnaB'><b id='PhnaB'><form id='PhnaB'><ins id='PhnaB'></ins><ul id='PhnaB'></ul><sub id='PhnaB'></sub></form><legend id='PhnaB'></legend><bdo id='PhnaB'><pre id='PhnaB'><center id='PhnaB'></center></pre></bdo></b><th id='PhnaB'></th></span></q></dt></tr></i><div id='PhnaB'><tfoot id='PhnaB'></tfoot><dl id='PhnaB'><fieldset id='PhnaB'></fieldset></dl></div>

      <tfoot id='PhnaB'></tfoot>

    1. <small id='PhnaB'></small><noframes id='PhnaB'>

      <legend id='PhnaB'><style id='PhnaB'><dir id='PhnaB'><q id='PhnaB'></q></dir></style></legend>
        <bdo id='PhnaB'></bdo><ul id='PhnaB'></ul>

        修复了滚动 div 内的 div

        Fixed div inside scrolling div(修复了滚动 div 内的 div)
            1. <i id='sZEOS'><tr id='sZEOS'><dt id='sZEOS'><q id='sZEOS'><span id='sZEOS'><b id='sZEOS'><form id='sZEOS'><ins id='sZEOS'></ins><ul id='sZEOS'></ul><sub id='sZEOS'></sub></form><legend id='sZEOS'></legend><bdo id='sZEOS'><pre id='sZEOS'><center id='sZEOS'></center></pre></bdo></b><th id='sZEOS'></th></span></q></dt></tr></i><div id='sZEOS'><tfoot id='sZEOS'></tfoot><dl id='sZEOS'><fieldset id='sZEOS'></fieldset></dl></div>

              <legend id='sZEOS'><style id='sZEOS'><dir id='sZEOS'><q id='sZEOS'></q></dir></style></legend>

              <tfoot id='sZEOS'></tfoot>
                <tbody id='sZEOS'></tbody>
                <bdo id='sZEOS'></bdo><ul id='sZEOS'></ul>
                1. <small id='sZEOS'></small><noframes id='sZEOS'>

                2. 本文介绍了修复了滚动 div 内的 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要只在鼠标悬停在滚动条上时修复具有 980px 宽度500px 高度 (class="main") 的网站的主要部分div 的 height 为 1500pxwidth 为 100% (class="container-scroll"),它位于其他 div 中,height 为 500px. (class="container")

                  I need to make the main of my site that has 980px width and 500px height (class="main") be fixed only when the mouse is over a scrolling div and has a height of 1500px and a width of 100% (class="container-scroll"), that is inside other div with height of 500px. (class="container")

                  很困惑,对吧?

                  我做了一个fiddle,我快到了,问题是如果我将main设置为fixed,它会随着页面滚动,而不仅仅是div内部

                  I made a fiddle, I'm almost there, the problem is that if I set up the main to fixed, it will scroll with the page , not just inside the div

                  这是我的小提琴:https://jsfiddle.net/8oj0sge4/1/embedded/result/

                  HTML:

                  <div id="wrapper">
                      <div class="container">
                          <div class="container-scroll">
                              <div class="main">
                  
                              </div>
                          </div>
                      </div>
                  </div>
                  

                  CSS:

                      #wrapper {
                          width: 100%;
                          height: 1500px;
                          border: 1px solid red;
                          padding-top: 380px;
                      }
                      #wrapper .container {
                          border: 1px solid green;
                          width: 100%;
                          height: 500px;
                          overflow: scroll;
                      }
                      #wrapper .container-scroll {
                          height: 1500px;
                          width: 100%;
                          border: 1px solid yellow;
                      }
                      #wrapper .main {
                          width: 980px;
                          height: 500px;
                          background: black;
                          overflow: scroll;
                          /*position: fixed;*/
                      }
                  

                  推荐答案

                  如果我理解正确的话,你希望主 div 保持在父 div 的顶部吗?

                  If I'm understanding this correctly, you want the main div to stay on the top of the parent div?

                  小提琴:https://jsfiddle.net/8oj0sge4/3/ (完整)

                  所做的更改:

                  • #wrapper .main:添加了position:absolute(固定"到父级)
                  • #wrapper .container-scroll:添加 position: relative(确定要修复"到哪个父级)
                  • 在主 div 中添加了一个 id(为方便起见)
                  • #wrapper .main: Added position:absolute ("fixed" to parent)
                  • #wrapper .container-scroll: Added position: relative (determines what parent to "fix" to)
                  • Added an id to the main div (for convenience)

                  JavaScript 代码:

                  JavaScript code:

                  var main = document.getElementById('main-site');
                  var maxTop = main.parentNode.scrollHeight-main.offsetHeight; // Make sure we don't go outside the parent
                  
                  main.parentNode.parentNode.onscroll = function() {
                     main.style.top = Math.min(this.scrollTop,maxTop) + "px";
                  }
                  

                  这篇关于修复了滚动 div 内的 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  Embed YouTube video - Refused to display in a frame because it set #39;X-Frame-Options#39; to #39;SAMEORIGIN#39;(嵌入 YouTube 视频 - 拒绝显示在框架中,因为它将“X-Frame-Options设置为“SAMEORIGIN)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)

                  <small id='0xvNU'></small><noframes id='0xvNU'>

                  • <tfoot id='0xvNU'></tfoot>
                    • <bdo id='0xvNU'></bdo><ul id='0xvNU'></ul>

                          1. <legend id='0xvNU'><style id='0xvNU'><dir id='0xvNU'><q id='0xvNU'></q></dir></style></legend>

                          2. <i id='0xvNU'><tr id='0xvNU'><dt id='0xvNU'><q id='0xvNU'><span id='0xvNU'><b id='0xvNU'><form id='0xvNU'><ins id='0xvNU'></ins><ul id='0xvNU'></ul><sub id='0xvNU'></sub></form><legend id='0xvNU'></legend><bdo id='0xvNU'><pre id='0xvNU'><center id='0xvNU'></center></pre></bdo></b><th id='0xvNU'></th></span></q></dt></tr></i><div id='0xvNU'><tfoot id='0xvNU'></tfoot><dl id='0xvNU'><fieldset id='0xvNU'></fieldset></dl></div>
                              <tbody id='0xvNU'></tbody>