Last active
November 27, 2019 17:13
-
-
Save redamoon/92d1c3073cbb8c85a90d84cbed2c64ca to your computer and use it in GitHub Desktop.
position sticky load scrollLeft End
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- <div class="table-wrap"> | |
<table> | |
<tr> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>テスト</th> | |
<th>2019(最新年)</th> | |
</tr> | |
</table> | |
</div> --> | |
<div class="sticky-wrap"> | |
<table class="sticky"> | |
<thead> | |
<tr> | |
<th>左固定</th> | |
<th class="top_heading">見出し</th> | |
<th class="top_heading">見出し</th> | |
<th class="top_heading">見出し</th> | |
<th class="top_heading">見出し</th> | |
<th class="top_heading">最後</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<th>左見出し</th> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
</tr> | |
<tr> | |
<th>左見出し</th> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
<td>テキスト</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $(window).on('load', function() { | |
// const w = $('.table-wrap > table').outerWidth() | |
// console.log(w) | |
// $('.table-wrap').scrollLeft(w) | |
// }) | |
let totalWidth = 0 | |
$('.top_heading').each(function(index) { | |
totalWidth += parseInt($(this).width(), 10); | |
}) | |
console.log(totalWidth) | |
$(window).on('load', function() { | |
$('.sticky-wrap').scrollLeft(totalWidth) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.table-wrap { | |
width: 200px; | |
display: block; | |
overflow-x: scroll; | |
white-space: nowrap; | |
-webkit-overflow-scrolling: touch; | |
} | |
.table-wrap table { | |
width: 100%; | |
} | |
.sticky-wrap { | |
width: 400px; | |
// height: 300px; | |
overflow: scroll; | |
} | |
.sticky { | |
table-layout: fixed; | |
width: 100%; | |
border-collapse: collapse; | |
border: 1px solid | |
#CCC; | |
thead tr th { | |
width: 100px; | |
position: sticky; | |
left: 0; | |
z-index: 3; | |
} | |
.top_heading { | |
position: sticky; | |
top: 0; | |
z-index: 2; | |
} | |
tbody tr th { | |
position: sticky; | |
left: 0; | |
z-index: 3; | |
} | |
th { | |
background: #DCDCDC | |
} | |
th, td { | |
padding: 5px; | |
border-collapse: collapse; | |
border: 1px solid #CCC; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment