javascript - 从右向左滚动时无法删除左侧的空白区域

标签 javascript css angularjs

我正在研究 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时没有显示额外的空白,但根据我的要求,我需要使用它来使水平滚动条从右向左滚动。

最佳答案

其中一个 div 有:

div {
  left: -1000px
}

它可以通过其 aria-label 进行识别和定位:

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

jsfiddle

关于javascript - 从右向左滚动时无法删除左侧的空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46119605/

相关文章:

javascript - 物理模拟基础

javascript - 在一行中验证文本字段

html - 均匀或均等地分配 DIVS……是的,我知道我应该使用表格

javascript - 当我转换它们时,div 左侧出现一条线

javascript - 强制前端的 http 请求超时

angularjs - Karma : Running test with phantomjs ends-up with TypeError, 而 Chrome 成功

javascript - AngularJS : How to auto-select date

javascript - 工具栏隐藏在 listView 中向上滚动但向下滚动时不会返回

javascript - 如何创建使用node和mongodb发送邮件的api

html - 下拉列表在 CSS HTML 中显示用户的图像和名称