美文网首页
关于加了position:fixed的浏览器滚动问题

关于加了position:fixed的浏览器滚动问题

作者: 古德毛宁_39de | 来源:发表于2018-02-21 21:24 被阅读0次
    顶部导航栏加了position:fixed属性后,当窗口缩放后拉动滚动条,顶部导航栏不随之滚动,

    我们可以这样解决

    在js代码中加如下代码:

    window.onscroll = function() {

    var sl = -Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);

    document.getElementById('fixed').style.left = sl + 'px';

    console.log(sl);

    }

    可能在手机浏览时还会出现这个问题再把它的css代码加上overflow-x: hidden即可

    .head {

    background: #fff;

    position: fixed;

    z-index: 100;

    min-width: 1200px;

        height: 60px;

        background: #fff;

        top: 0;

        bottom: 0;

      /* overflow-x: scroll;*/

        overflow-x: hidden;

    }

    相关文章

      网友评论

          本文标题:关于加了position:fixed的浏览器滚动问题

          本文链接:https://www.haomeiwen.com/subject/cygotftx.html