Skip to content

Instantly share code, notes, and snippets.

@pocari
Created April 14, 2014 13:19
Show Gist options
  • Save pocari/10647108 to your computer and use it in GitHub Desktop.
Save pocari/10647108 to your computer and use it in GitHub Desktop.
scroll template
<html>
<head>
<script>
function $id(id) {
return document.getElementById(id);
}
function test(){
alert($id("top_label").style.width);
alert($id("left_label").style.height);
}
function xscroll(top_header, left_header, contents, width, height) {
xyscroll_base(top_header, left_header, contents, width, height,
0, 16, "x_scroll_contents");
}
function yscroll(top_header, left_header, contents, width, height) {
xyscroll_base(top_header, left_header, contents, width, height,
16, 0, "y_scroll_contents");
}
function xyscroll(top_header, left_header, contents, width, height) {
xyscroll_base(top_header, left_header, contents, width, height,
16, 16, "xy_scroll_contents");
}
function xyscroll_base(top_header, left_header, contents, width,
height, xoffset, yoffset, contents_class) {
$id(contents).style.width = width;
$id(contents).style.height = height;
$id(contents).className = contents_class;
$id(top_header).style.width = width - xoffset;
$id(left_header).style.height = height - yoffset;
$id(contents).onscroll = function () {
$id(top_header).scrollLeft = $id(contents).scrollLeft;
$id(left_header).scrollTop = $id(contents).scrollTop;
}
}
</script>
<style type="text/css">
.scroll_left_label {
overflow:hidden;
}
.scroll_top_label {
overflow:hidden;
}
.y_scroll_contents {
overflow-y:scroll;
overflow-x:hidden;
}
.x_scroll_contents {
overflow-y:hidden;
overflow-x:scroll;
}
.xy_scroll_contents {
overflow-x:scroll;
overflow-y:scroll;
}
table.layout {
border-width:0;
border-style:solid;
border-collapse:collapse;
border-spacing:0px;
}
table.layout td {
border-width:0px;
border-style:solid;
border-collapse: collapse;
border-spacing: 0px;
}
table.grid {
border: 0px;
border-color:black;
border-style:solid;
border-collapse: collapse;
border-spacing: 0px;
}
table.grid td {
font-size:9pt;
white-space:nowrap;
border-color:black;
border-width:1px;
border-style:solid;
border-collapse: collapse;
border-spacing: 0px;
white-space: nowrap;
}
table.grid tr.header {
background-color:#afeeee;
}
}
</style>
</head>
<body>
<input type="button" value="チェック" onclick="test()" />
<!--
スクロール用にそれぞれの部分を保持するための、2x2の外枠テーブルを作成する。
+-----------------------------+
|固定ヘッダ用テーブル    |横可変ヘッダ用テーブル   |
+--------------+--------------+
|縦可変ヘッダ用テーブル   |データ用テーブル      |
+--------------+--------------+
-->
<table cellpadding="0" class="layout">
<tr>
<!--
固定ヘッダ部分
+-----------------------------+
|固定ヘッダ用テーブル    |              |
+--------------+--------------+
|              |              |
+--------------+--------------+
固定ヘッダ部分のtableには特にclassの指定無し
-->
<td valign="top" halign="left">
<table class="grid">
<tr class="header">
<td nowrap width="100">固定ヘッダ1</td>
<td nowrap width="100">固定ヘッダ2</td>
</tr>
</table>
</td>
<td valign="top" halign="left">
<!--
+-----------------------------+
|              |横可変ヘッダ用テーブル   |
+--------------+--------------+
|              |              |
+--------------+--------------+
横可変ヘッダ用テーブルはclass="scroll_top_label"を指定し、javascriptに渡すための、idを任意で設定する(ここではtop_label)
-->
<div class="scroll_top_label" id="top_label">
<table class="grid">
<tr class="header">
<td nowrap width="150">可変ヘッダ1</td>
<td nowrap width="150">可変ヘッダ2</td>
<td nowrap width="150">可変ヘッダ3</td>
<td nowrap width="150">可変ヘッダ4</td>
<td nowrap width="150">可変ヘッダ5</td>
<td nowrap width="150">可変ヘッダ6</td>
<td nowrap width="150">可変ヘッダ7</td>
<td nowrap width="150">可変ヘッダ8</td>
<td nowrap width="150">可変ヘッダ9</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<!--
+-----------------------------+
|              |              |
+--------------+--------------+
|縦可変ヘッダ用テーブル   |              |
+--------------+--------------+
縦可変ヘッダ用テーブルはclass="scroll_left_label"を指定し、javascriptに渡すための、idを任意で設定する(ここではleft_label)
-->
<td valign="top" halign="left">
<div class="scroll_left_label" id="left_label">
<table class="grid">
<tr class="header">
<td nowrap width="100">項目1-1</td>
<td nowrap width="100">項目1-2</td>
</tr>
<tr class="header">
<td>項目2-1</td>
<td>項目2-2</td>
</tr>
<tr class="header">
<td>項目3-1</td>
<td>項目3-2</td>
</tr>
<tr class="header">
<td>項目4-1</td>
<td>項目4-2</td>
</tr>
<tr class="header">
<td>項目5-1</td>
<td>項目5-2</td>
</tr>
<tr class="header">
<td>項目6-1</td>
<td>項目6-2</td>
</tr>
<tr class="header">
<td>項目7-1</td>
<td>項目7-2</td>
</tr>
<tr class="header">
<td>項目8-1</td>
<td>項目8-2</td>
</tr>
<tr class="header">
<td>項目9-1</td>
<td>項目9-2</td>
</tr>
</table>
</div>
</td>
<!--
+-----------------------------+
|              |              |
+--------------+--------------+
|              |データ用テーブル      |
+--------------+--------------+
データ用テーブルはjavascriptに渡すための、idを任意で設定する(ここではcontents)
CSSのクラスは各スクロール設定関数
xscroll
yscroll
xyscroll
の中で、実行時に設定される。
-->
<td valign="top" halign="left">
<div id="contents">
<table class="grid">
<tr>
<td nowrap width="150">データ1-1</td>
<td nowrap width="150">データ1-2</td>
<td nowrap width="150">データ1-3</td>
<td nowrap width="150">データ1-4</td>
<td nowrap width="150">データ1-5</td>
<td nowrap width="150">データ1-6</td>
<td nowrap width="150">データ1-7</td>
<td nowrap width="150">データ1-8</td>
<td nowrap width="150">データ1-9</td>
</tr>
<tr>
<td>データ2-1</td>
<td>データ2-2</td>
<td>データ2-3</td>
<td>データ2-4</td>
<td>データ2-5</td>
<td>データ2-6</td>
<td>データ2-7</td>
<td>データ2-8</td>
<td>データ2-9</td>
</tr>
<tr>
<td>データ3-1</td>
<td>データ3-2</td>
<td>データ3-3</td>
<td>データ3-4</td>
<td>データ3-5</td>
<td>データ3-6</td>
<td>データ3-7</td>
<td>データ3-8</td>
<td>データ3-9</td>
</tr>
<tr>
<td>データ4-1</td>
<td>データ4-2</td>
<td>データ4-3</td>
<td>データ4-4</td>
<td>データ4-5</td>
<td>データ4-6</td>
<td>データ4-7</td>
<td>データ4-8</td>
<td>データ4-9</td>
</tr>
<tr>
<td>データ5-1</td>
<td>データ5-2</td>
<td>データ5-3</td>
<td>データ5-4</td>
<td>データ5-5</td>
<td>データ5-6</td>
<td>データ5-7</td>
<td>データ5-8</td>
<td>データ5-9</td>
</tr>
<tr>
<td>データ6-1</td>
<td>データ6-2</td>
<td>データ6-3</td>
<td>データ6-4</td>
<td>データ6-5</td>
<td>データ6-6</td>
<td>データ6-7</td>
<td>データ6-8</td>
<td>データ6-9</td>
</tr>
<tr>
<td>データ7-1</td>
<td>データ7-2</td>
<td>データ7-3</td>
<td>データ7-4</td>
<td>データ7-5</td>
<td>データ7-6</td>
<td>データ7-7</td>
<td>データ7-8</td>
<td>データ7-9</td>
</tr>
<tr>
<td>データ8-1</td>
<td>データ8-2</td>
<td>データ8-3</td>
<td>データ8-4</td>
<td>データ8-5</td>
<td>データ8-6</td>
<td>データ8-7</td>
<td>データ8-8</td>
<td>データ8-9</td>
</tr>
<tr>
<td>データ9-1</td>
<td>データ9-2</td>
<td>データ9-3</td>
<td>データ9-4</td>
<td>データ9-5</td>
<td>データ9-6</td>
<td>データ9-7</td>
<td>データ9-8</td>
<td>データ9-9</td>
</tr>
</table>
</div>
<!--
最後にどのタイプのスクロールバーにするかを指定する。
xyscroll・・・縦横スクロール
xscroll・・・横スクロール
yscroll・・・縦スクロール
引数はそれぞれ
  上側ヘッダ部分のdivのid(横スクロールに連動して動く見出し)
  左側ヘッダ部分のdivのid(縦スクロールに連動して動く見出し)
  データ部分のdivのid
  データ部分のwidth
  データ部分のheight
を指定する。
-->
<script>
xyscroll("top_label", "left_label", "contents", 500, 100);
//xscroll("top_label", "left_label", "contents", 500, 100);
//yscroll("top_label", "left_label", "contents", 500, 100);
</script>
</td>
</tr>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment