是的,这可以通过 HTML 上的 JavaScript 和 CSS 实现;-)
查看我在http://www.w3schools.com/html/tryit.asp?filename=tryhtml_basic 中为您制作的代码
只需复制并粘贴以查看其工作原理,我认为不需要解释。
我希望这回答了你的问题?因为我并不清楚你需要什么。
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
#content
{
width: 200px;
overflow-x: hidden;
overflow-y: auto;
white-space: pre;
background-color: red;
}
#scrollbar
{
width: 200px;
overflow-x: scroll;
overflow-y: hidden;
/*set background color to transparent, to remove the blue line on top of the scrollbar*/
background-color: blue;
}
#innerScrollbar
{
height: 1px;
line-height: 1px;
font-size: 1px;
visibility: hidden;
background-color: yellow;
}
</style>
<script type="text/javascript">
//getting scrollbar width of browser, copied from (and thanks to) http://www.alexandre-gomes.com/?p=115
function getScrollBarWidth()
{
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";
var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner);
document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2) w2 = outer.clientWidth;
document.body.removeChild (outer);
return (w1 - w2);
};
//update scrollbar on page load, and when scrolling the content
function updateScrollbar(content, scrollbar)
{
scrollbar.getElementsByTagName('*')[0].style.width = content.scrollWidth + "px";
content.scrollLeft = scrollbar.scrollLeft;
}
</script>
</head>
<body onload="updateScrollbar(document.getElementById('content'), document.getElementById('scrollbar'))">
<div id="content">Here goes the content, you can now place the scrollbar div anywhere else you wish. But keep in mind that the scrollbar itself will still be the scrollbar of the browser/OS.</div>
...other website stuff goes here...
<div id="scrollbar" onscroll="updateScrollbar(document.getElementById('content'), this)"><div id="innerScrollbar"><!--dummy text--></div></div>
<script type="text/javascript">
//update scrollbar-container height, to height of scrollbar + 1,
//without a tiny bit of content visible, the scrollbar will not show at all!
document.getElementById('scrollbar').style.height =(getScrollBarWidth() + 1) + "px";
</script>
</body>
</html>
等等,我重读了你的问题,我似乎很清楚你想要什么。所以你可以打印 X 个表格,你可以在其中滚动 Y 轴。在表格的底部,您放置滚动条 div,您必须稍微调整一下 javascript 并循环遍历表格:
innerscrollbar.style.width = maxWidthFromTables + "px";
tables[i].scrollLeft = scrollbar.scrollLeft;
您将需要检索 maxWidthFromTables,当使用不同宽度的表格时,只需从以下位置获取最大宽度:tables[i].scrollWidth;