javascript - z-index 停止滚动页面的标题会影响页面内的其他滚动条

标签 javascript jquery html css

我正在使用 z-index 停止滚动页面的标题,如下所示

.headerscrolling{
z-index:9005;
}

我还在页面中心使用 niceScroll Jquery,它将使用以下命令根据 div(比如 id=innerscroll)内容动态创建滚动条。

<div id="innerscroll">

&Jquery 是

$("#innerscroll").getNiceScroll().resize();

现在的问题是,Nice Scroll bar 上升了 innerscroll div header 的像素高度。请建议我可以做些什么来克服这个问题

注意:如果我不使用 z-index ,它工作正常;

图表中的 PFB 问题: enter image description here

最佳答案

这里的固定标题菜单是滚动时下拉的重复菜单。

Js

var lastScrollPosition = 0;

    function handleScroll(){
    setTimeout(function(){
        var currentScrollPosition = window.pageYOffset;
        (currentScrollPosition - lastScrollPosition > 0) ? handleScrollDown() : handleScrollUp();   
        lastScrollPosition = currentScrollPosition;
    },0);

}

function handleScrollDown(){

    //if header menu is not in view then no point in checking if it is going out of view
    if(!isheaderMenuTopInView) return;      
    //console.log('inview going out');
    var windowTop = $(window).scrollTop(),
    headerMenuTop = $('#header-menu').offset().top,
    headerMenuBottom = headerMenuTop + $('#header-menu').height();
    if(headerMenuBottom < (windowTop+$('#fixed-header-menu').height())) {
        //console.log('went out of view');
        $('#fixed-header-menu').show(0);
        isheaderMenuTopInView = false;
    }
}

function handleScrollUp(){

    //if header menu is in view then no point in checking if it is coming in view
    if(isheaderMenuTopInView) return;
    //console.log('not in view coming in');
    var windowTop = $(window).scrollTop(),
    headerMenuTop = $('#header-menu').offset().top,
    headerMenuBottom = headerMenuTop + $('#header-menu').height();
    if(headerMenuBottom > (windowTop+$('#fixed-header-menu').height())){
        //console.log('came in view');
        $('#fixed-header-menu').hide(0);
        isheaderMenuTopInView = true;
    }
}

固定标题菜单是标题菜单的副本

<div id = 'headerContainer' class = 'span-12-of-12'>
    <nav>
        <div id = 'fixed-header-menu' class = 'span-12-of-12 menu section group'>                       
            <img class = 'menu-bg' src = './res/MenuBar.png' />
            <div class = 'col span-1-of-5 menu-item'><img src = './res/home.png' />Home</div>
            <div class = 'col span-1-of-5 menu-item'><img src = './res/aboutUs.png' />About Us</div>
            <div class = 'posture-position pp1 menu-item col span-1-of-5'>
                <img class = 'p1' src = './res/posture/p1.png' />
                <img class = 'p2' src = './res/posture/p12.png' />
            </div>
            <div class = 'col span-1-of-5 menu-item'><img src = './res/contactUs.png' />Contact Us</div>
            <div class = 'col span-1-of-5 menu-item'><img src = './res/gallery.png' />Gallery</div>     
        </div>  
    </nav>

    <div class = 'section group'>                   
        <div class='logo-name  span-3-of-12'>
            <img src = './res/LogoName.png' />
        </div>                  
    </div>  
    <nav>
        <div id = 'header-menu' class = 'menu section group'>                       
            <img class = 'menu-bg' src = './res/MenuBar.png' />
            <div class = 'col span-1-of-5 menu-item'><img src = './res/home.png' />Home</div>
            <div class = 'col span-1-of-5 menu-item'><img src = './res/aboutUs.png' />About Us</div>
            <div class = 'posture-position pp1 menu-item col span-1-of-5'>
                <img class = 'p1' src = './res/posture/p1.png' />
                <img class = 'p2' src = './res/posture/p12.png' />
            </div>
            <div class = 'col span-1-of-5 menu-item'><img src = './res/contactUs.png' />Contact Us</div>
            <div class = 'col span-1-of-5 menu-item'><img src = './res/gallery.png' />Gallery</div>     
        </div>  
    </nav>
</div> 

如果你有任何疑问,请回来

关于javascript - z-index 停止滚动页面的标题会影响页面内的其他滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336490/

相关文章:

javascript - 需要一个正则表达式来验证长度为 6 到 25 个字符的字母数字

javascript - JQuery 响应式菜单不起作用

html - 在 Sinatra 表单中格式化日期字段

javascript - 如何获取元素边框的计算宽度?

javascript - 如何制作带有文件字段的隐藏表单

jquery - DIV 向左定位

php - 是 否 带有 javascript 链接删除功能的选项

javascript - 如何用javascript重写html文档

javascript - .every 方法不将所有元素与 IF 语句匹配

javascript - Chart.js : Is there a way to name each bubble in chart?