Можно ли объединить 3 полосы прокрутки в одну? У меня есть описанный ниже метод, который соединяет одну панель, но как мне это сделать, чтобы подключить более одной? Стол может иметь разную ширину. Я пробовал l oop через таблицы и использовал оператор +=
на scrollWrapper
, думая, что у него есть какой-то массив или список, который может содержать одиночное событие прокрутки, но похоже, что это не так.
let tables = document.querySelectorAll(".table");
let scrollWrapper = document.querySelector(".scroll-bar");
let scrollBar = scrollWrapper.querySelector(".bar");
scrollBar.setAttribute("style", "width: 2000px;");
scrollWrapper.onscroll = function()
{
tables[2].scrollLeft = scrollWrapper.scrollLeft;
}
tables[2].onscroll = function()
{
scrollWrapper.scrollLeft = tables[2].scrollLeft;
}
.main {
background-color: wheat;
}
.wrapper {
width: 300px;
}
.table {
overflow-x: scroll;
}
.table table{
width: 1000px;
}
.table th,
.table td{
padding: 3px 10px;
}
.scroll-bar {
height: 20px;
width: 100%;
background-color: pink;
overflow-x: scroll;
}
.scroll-bar .bar {
height: 1px;
}
<div class="main">
<div class="wrapper">
<div class="table">
<table>
<thead>
<tr>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
</tr>
</tbody>
</table>
</div>
<div class="table">
<table>
<thead>
<tr>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
</tr>
</tbody>
</table>
</div>
<div class="table">
<table>
<thead>
<tr>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
<th>Some header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
<td>Some text</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="scroll-bar">
<div class="bar"></div>
</div>
</div>