我在尝试将滚动应用到我的 HTML 时遇到问题。这个想法是有一个网格。可以垂直滚动。但我也想让该网格的一部分水平滚动。
作为奖励,我不希望任何滚动条可见,我将在 Android 上使用 WebView 使用它。
我正在摆弄几个组件的溢出,但我通常最终得到:
- 能够水平滚动整个网格,而不仅仅是“数据”div。
- 'data' 和 'header' div 有 2 个单独的垂直滚动条。
我的 HTML:
<button id='scroll_up'>scroll up</button>
<button id='scroll_down'>scroll down</button>
<button id='scroll_left'>scroll left</button>
<button id='scroll_right'>scroll right</button>
<div id="grid">
<div id="header">
<a id='row_header'>Some Header</a>
<a class="row">1</a>
<a class="row">2</a>
<a class="row">3</a>
<a class="row">4</a>
<a class="row">5</a>
<a class="row">6</a>
<a class="row">7</a>
<a class="row">8</a>
<a class="row">9</a>
<a class="row">10</a>
<a class="row">11</a>
<a class="row">12</a>
<a class="row">13</a>
<a class="row">14</a>
<a class="row">15</a>
<a class="row">16</a>
<a class="row">17</a>
<a class="row">18</a>
<a class="row">19</a>
<a class="row">20</a>
</div>
<div id="data">
<div id="column_header">
<a class="header">h1</a>
<a class="header">h2</a>
<a class="header">h3</a>
<a class="header">h4</a>
<a class="header">h5</a>
<a class="header">h6</a>
<a class="header">h7</a>
<a class="header">h8</a>
<a class="header">h9</a>
<a class="header">h10</a>
<a class="header">h11</a>
<a class="header">h12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
<div class="row_data">
<a class="data">data 1</a>
<a class="data">data 2</a>
<a class="data">data 3</a>
<a class="data">data 4</a>
<a class="data">data 5</a>
<a class="data">data 6</a>
<a class="data">data 7</a>
<a class="data">data 8</a>
<a class="data">data 9</a>
<a class="data">data 10</a>
<a class="data">data 11</a>
<a class="data">data 12</a>
</div>
</div>
</div>
CSS:
body {
font: 18px arial,sans-serif;
}
#grid {
display: block;
position: absolute;
top: 100px;
left: 0px;
width: 100%;
height: 517px;
margin: 0;
}
#header {
display: inline-block;
width: 25%;
height: 100%;
float: left;
overflow: auto;
}
#data {
float: left;
display: inline-block;
width: 75%;
height: 100%;
overflow: auto;
}
.row, #row_header {
display: block;
padding-left: 8px;
height: 50px;
border: 1px solid black;
text-align: center;
line-height: 50px;
}
.row_data, #column_header {
display: inline-block;
white-space: nowrap;
width: 100%;
}
.data, .header {
display: inline-block;
border: 1px solid black;
width: 20%;
}
#row_header, .header {
height: 30px;
line-height: 30px;
}
#row_header, #column_header {
text-align: center;
}
.data, .row {
height: 50px;
text-align: center;
line-height: 50px;
}
还有我的 JS:
$(document).ready(function() {
$('#scroll_up').click(function() {
var height = $('#grid').height();
$('#grid').scrollTo( '-=' + height + 'px', { axis:'y' } );
});
$('#scroll_down').click(function() {
var height = $('#grid').height();
$('#grid').scrollTo( '+=' + height + 'px', { axis:'y' } );
});
$('#scroll_left').click(function() {
var width = $('#data').width();
$('#data').scrollTo( '-=' + width + 'px', { axis:'x' } );
});
$('#scroll_right').click(function() {
var width = $('#data').width();
$('#data').scrollTo( '+=' + width + 'px', { axis:'x' } );
});
});
为方便起见:http : //jsfiddle.net/xFPtj/1/
关于我应该做什么的任何提示?