在溢出-y的div内的画布

时间:2012-07-21 13:45:32

标签: css html5 canvas scrollbar

我有一个带溢出y的div,里面有一个画布。 当我向下滚动时,我会在FF,Chrome和IE9的底部找到一个条带。 如何让这条带消失?

可以看到红色条带here

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }

  #container {
    overflow-y: scroll;
    width: 900px;
    height: 400px;
    background-color: red;
  }

  #container canvas {
    background-color: gray;
  }
</style>
<script type="text/javascript">
  var init = function() {
    var container = document.getElementById('container');
    var canvas = document.createElement('canvas');
    canvas.width = container.clientWidth;
    canvas.height = 1000;
    container.appendChild(canvas);
    container.scrollTop = container.scrollHeight;
  }
  </script>
</head>
<body onload="init()">
  <div id="container"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

display: block;中添加#container canvas

#container canvas {
    background-color: gray;
    display: block;
}

Demo