【问题标题】:nanoScrollbar does not work when mouse wheel used inside the DIV在 DIV 内使用鼠标滚轮时 nano 滚动条不起作用
【发布时间】:2013-12-20 11:55:42
【问题描述】:

我正在尝试制作两行 CSS 网页布局并适合可用的窗口高度。如果底部 div 高度上的内容应该使用纳米滚动显示滚动条。代码如下。

当在内容 div 内使用鼠标滚轮时,它不会移动纳米滚动。只有当您将鼠标移动到纳米滚动的顶部并进行滚动时,它才会起作用。

    <html>
    <head>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }

            html, body, .Container, .myContent {
                height: 100%;
            }

                .Container:before {
                    content: '';
                    height: 100%;
                    float: left;
                }

            .HeightTaker {
                position: relative;
                z-index: 1;
            }

            .HeightTaker:after {
                content: '';
                clear: both;
                display: block;
            }

            .Wrapper {
                position: absolute;
                width: 100%;
                height: 100%;
            }

            .myContent {
                overflow: inherit;
                background-color: #66cab7;
                text-align: center;
            }

            .Header {
                background-color: #bf5b5b;
                text-align: center;
            }

            /** nano css **/
            .nano {
                position: relative;
                width: 100%;
                height: 100%;
                overflow: hidden;
            }

            .nano .nano-content {
                position: absolute;
                overflow: scroll;
                overflow-x: hidden;
                top: 0;
                right: 0;
                bottom: 0;
                left: 0;
            }

            nano .nano-content:focus {
                outline: thin dotted;
            }

            .nano .nano-content::-webkit-scrollbar {
                visibility: hidden;
            }

            .has-scrollbar .nano-content::-webkit-scrollbar {
                visibility: visible;
            }

            .nano > .pane {
                background: rgba(0,0,0,.25);
                position: absolute;
                width: 10px;
                right: 0;
                top: 0;
                bottom: 0;
                visibility: hidden\9; /* Target only IE7 and IE8 with this hack */
                opacity: .01;
                -webkit-transition: .2s;
                -moz-transition: .2s;
                -o-transition: .2s;
                transition: .2s;
                -moz-border-radius: 5px;
                -webkit-border-radius: 5px;
                border-radius: 5px;
            }

            .nano > .pane > .slider {
                background: #444;
                background: rgba(0,0,0,.5);
                position: relative;
                margin: 0 1px;
                -moz-border-radius: 3px;
                -webkit-border-radius: 3px;
                border-radius: 3px;
            }

            .nano:hover > .pane, .pane.active, .pane.flashed {
                visibility: visible\9; /* Target only IE7 and IE8 with this hack */
                opacity: 0.99;
            }
        </style>
        <script src="https://dl.dropboxusercontent.com/u/2781659/js/jquery-2.0.3.js" type="text/javascript"></script>
        <script src="https://dl.dropboxusercontent.com/u/2781659/js/jquery.nanoscroller.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(function () {
                $(".nano").nanoScroller();
            });
        </script>
    </head>
    <body>
        <div class="Container">
            <div class="Header">
                <h1>Header</h1>
                <p>if The Header height is not fixed, It will span excatly his needed space.</p>
                <p>The Padding/Margin between the header and the content and around the layout is optional</p>

            </div>
            <div class="HeightTaker">
                <div class="Wrapper">
                    <div class="nano">
                        <div class="content myContent">
                            <h1>Content</h1>
                            <p>The Content div should always span the available Container space.</p>
                            <p>If the content exceed the Content available space, it will scroll.</p>
                            <p><a target="_blank" href="http://jsfiddle.net/avrahamcool/58mkp/">Here's a demo of this scenario</a></p>
                            <p class="Important">This Layout has been tested on: IE10, IE9, IE8, FireFox, Chrome, Safari, Opera. using Pure CSS 2.1 only</p>
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                            test<br />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>

【问题讨论】:

  • overflow: inherit; 应用于 myContent 有效,但只能通过鼠标单击滚动。
  • 感谢 Anup,但我无法使用此解决方案,因为我无法限制用户在滚动条上拖动鼠标以继续工作。感谢您的帮助

标签: jquery css scroll


【解决方案1】:

我认为,你需要使用 jscrollpane js。试试这个js。

http://jscrollpane.kelvinluck.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    相关资源
    最近更新 更多