【问题标题】:unable to remove white blank space on left hand side when scrolled from right to left从右向左滚动时无法删除左侧的空白区域
【发布时间】:2018-02-17 13:33:13
【问题描述】:

我正在研究 angularjs 谷歌图表。我想显示图表的水平滚动条,默认情况下应该从右向左滚动。

示例演示http://jsfiddle.net/uzbozqz4/

为了让滚动条默认从右向左滚动,我使用了下面 style 属性中定义的以下 css 代码:

 <div id="chart_div" style="margin-left:0;white-space: nowrap;overflow-x:auto;overflow-y:hidden;direction:rtl;left:0;top:0;height: 500px;"></div>

direction:rtl 使滚动条从右向左滚动,这是必需的,但问题是我可以看到从右向左滚动时左侧有很多空白。我尝试使用 left-padding:0px;但它仍然显示空格。关于从右向左滚动时如何删除左侧多余空白的任何建议?

代码:

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses'],
          ['2004',  1000,      400],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540]
        ]);

        var options = {
          title: 'Company Performance',
          hAxis: {title: 'Year', titleTextStyle: {color: 'red'}},

        };
   var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="margin-left:0;white-space: nowrap;overflow-x:auto;overflow-y:hidden;direction:rtl;left:0;top:0;height: 500px;"></div>
  </body>

</html>

PS:当我删除direction:rtl 时没有显示额外的空格,但根据我的要求,我需要使用它来使水平滚动条从右向左滚动。

【问题讨论】:

    标签: javascript css angularjs


    【解决方案1】:

    其中一个 div 有:

    div {
      left: -1000px
    }
    

    可以通过aria-label来识别和定位:

    div[aria-label="A tabular representation of the data in the chart."] {
      left: 0 !important;
    }
    

    jsfiddle

    【讨论】:

    • 但是滚动条丢失了,在显示某些条之后,我想要滚动条,以便用户可以从右到左滚动和查看条。@ovokuro
    • 缺少哪个滚动条?当我调整屏幕大小时,水平滚动条仍然可见
    • 在应用 css 代码从右到左滚动之前的工作演示:鼠标悬停时的工具提示按预期显示plnkr.co/edit/SwEUeCN8IoT0JN5RrvUx?p=preview 应用 css 代码从右到左滚动后的演示:问题是鼠标悬停时的工具提示bar 未按预期显示 plnkr.co/edit/INfdkrotpyo87fpdN9rR?p=preview 。按照建议应用css代码后,鼠标悬停在栏上的工具提示不起作用,有什么建议吗? @ovokuro
    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多