I'm having problems trying to apply scrolling to my HTML. The idea is to have a grid. Which can be scrolled vertically. But I also want to have a part of that grid be scrolled horizontally.
As a bonus I don't want any of the scrollbars visible, I will using it on Android using a WebView.
I'm fiddling with the overflow on several components, but I usually end up with:
- able to scroll the whole grid horizontally, instead of only the 'Data' div.
- have 2 seperate vertical scroll bars for both 'data' and 'header' divs.
My 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>
The 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;
}
And my 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' } );
});
});
For convienence: http://jsfiddle.net/xFPtj/1/
Any tips for what I should do?