【问题标题】:Scrollbar handles not visible滚动条手柄不可见
【发布时间】:2017-01-29 23:52:26
【问题描述】:

滚动条手柄在我的页面中不可见。我尝试将overflow-x 设置为自动并滚动#cust1 和#cust2 div。

我还需要五个 div 才能通过页面底部的一个滚动条控制它们的水平滚动。 (Div 的 #one、#two、#three、#four 和 #custTimeline)我不希望每个客户 div 都有滚动条。

请帮忙。 https://jsfiddle.net/c71ytuxz/1/

var c = document.getElementById("custTimeline");
var ctx = c.getContext("2d");
ctx.font = "20px Georgia";
ctx.save();
ctx.rotate(-90*Math.PI/180);

var baseLoc = 130;
var hours = ["5AM","6AM", "7AM","8AM","9AM","10AM","11AM","12 NOON","1PM","2PM","3PM","4PM","5PM","6PM", "7PM", "8PM", "9PM", "10PM", "11PM", "12PM"];

for(i = 0; i < hours.length; i++) {
  if (i == 0) {
     ctx.fillText(hours[i], -120, baseLoc);
  }  
  else {
     baseLoc += 90;
     ctx.fillText(hours[i], -120, baseLoc);  
  }
}
ctx.restore();
#header {
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100px;
  background: lightgrey;
}
#cust1 {
    position: fixed;
    left: 0px;
    top: 160px;
    width: 1500px;
    height: 150px;
    background: lightgrey;
    overflow-x: scroll;
    overflow-y: hidden;
    margin-bottom: 10px;
}
#one {
    width: 8%;
    height: 150px;
    background: darkgrey;
    float: left;   
    text-align: center;
}
#two {
    margin-left: 25%;
    width: 35px;
    height: 150px;
    background: green;
}

#cust2 {
    position: fixed;
    top: 320px;
    left: 0px;
    width: 1500px;
    height: 150px;
    background: lightgrey;
    overflow-x: scroll;
    overflow-y: hidden;
}
#three {
    width: 8%;
    height: 150px;
    background: darkgrey;
    float: left;
    text-align: center;
}
#four {
    margin-left: 15%;
    width: 35px;
    height: 150px;
    background: green;
}
<canvas id="custTimeline"
  width = "1900"
  height = "130"
  style = "border:3px solid #aaaaaa;">
</canvas>

<div id="cust1">
    <div id="one"><p>
    Customer 1
    </p></div>
    <div id="two"></div>
</div>

<div id="cust2">
    <div id="three"><p>
    Customer 2
    </p></div>
    <div id="four"></div>
</div>

【问题讨论】:

    标签: javascript css


    【解决方案1】:

    由于#cust1的宽度为1500px,滚动只会在其内容变宽时才会出现,目前只有8% (#one) + 25% + 35px (#two ) 的总和。

    如果你想让它滚动,改变这个

    #cust1 {
        position: fixed;
        left: 0px;
        top: 160px;
        width: 100vw;                    /*  changed property  */
        height: 150px;
        background: lightgrey;
        overflow-x: scroll;
        overflow-y: hidden;
        margin-bottom: 10px;
    }
    #two {
        margin-left: 25%;
        width: 1000px;                   /*  changed property  */
        height: 150px;
        background: green;
    }
    

    Updated fiddle


    根据评论更新

    要让一个滚动条更新另一个滚动条,这是一种方法,使用 jQuery。

    $(document).ready(function(){
        $( window ).scroll(function(){
            var position = $( this ).scrollLeft();
            $("#first").scrollLeft(position);
            $("#second").scrollLeft(position);
        });
    });
    

    【讨论】:

    • 绿色区域是到达时间指示器,它们应该是狭窄的。 #cust1 和 #cust2 div 分别设置为 1500 像素,这应该强制滚动条但不起作用。
    • @mike 这不是滚动条的工作原理......因为#cust1 和#cust2 有òverflow:auto,所以当它们的content 更大时它们会变得可滚动(活动滚动条)比它们宽,不是因为它们本身比视口宽……这就是为什么我将它们设置为 100vh 并使内容更宽,所以你会看到它是如何工作的
    • 谢谢,我明白了。我通过在“cust1”和“cust2”中创建另一个名为“filler1”和“filler2”的长 div 并将它们的不透明度设置为 0 来使其工作。jsfiddle 现在关于我的问题的另一部分,如何制作滚动条为“custTimeline”控制“cust1”和“cust2”?
    • 我创建了这个概念验证,但我无法将其应用于更大的示例。 JsFiddle
    • @mike 好吧,有两件事,首先 jQuery 没有加载,其次,您需要滚动 #cust1 和 #cust2,因为它们是滚动的...fiddle
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    相关资源
    最近更新 更多