jquery - 当在 DIV 中使用鼠标滚轮时,纳米滚动条不起作用

标签 jquery css scroll

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

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

    <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>

最佳答案

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

http://jscrollpane.kelvinluck.com/

关于jquery - 当在 DIV 中使用鼠标滚轮时,纳米滚动条不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20703129/

相关文章:

javascript - jQuery 选择最接近的所有子项

javascript - 绘制 DOM "pseudo"行

html - 设置具有固定宽度单元格的网格样式

html - 不需要的水平滚动

html - 在滚动条上可见时运行 css 动画

javascript - 在触摸设备上捕获并停止拖动

Javascript - 在写下文本区域之前更改输入字母

javascript - 使用 jquery tablesorter 插件保留斑马条纹

javascript - 使用选择下拉菜单而不是输入标签字段的日期选择器

javascript - 滚动 Div 到特定位置