In general, I scroll inside the table, the code I quote from below, why when I click for the first time, everything is OK, it scrolls to where itβs necessary and itβs logical that when I click again, Iβll essentially not have to scroll because I am already at the right positions. However, when I click through again, a scroll occurs in some random places.
$('#sc-wrap > .sc-controller').each( function(i, elem){ $(elem).attr('data-target', 'sc-position' + (i + 1) ); }); $('.sc-controller').click( function() { var target = $(this).attr('data-target'); var scrollTop = $('#'+target).offset().top; $('.sc-data').animate({ scrollTop: scrollTop }, 500) }) .sc-data{ max-height: 300px; overflow-y: scroll; } #sc-wrap{ display: flex; flex-wrap: wrap; overflow-y: hidden; z-index: 11; } #sc-wrap > .sc-controller{ background: #e61a1a; border-radius: 4px; padding: 7px 10px; margin-right: 5px; margin-bottom: 5px; margin-top: 0px; color: white; font-family: Lato, Arial, sans-serif; font-size: 14px;; cursor: pointer; transition: all .45s; } #sc-wrap > .sc-controller:hover{ background: #f33; } #sc-wrap > .sc-controller:last-child{ margin-right: 0; } <div id="sc-wrap"> <div class="sc-controller">ΠΠΎΠ·ΠΈΡΠΈΡ 1</div> <div class="sc-controller">ΠΠΎΠ·ΠΈΡΠΈΡ 2</div> <div class="sc-controller">ΠΠΎΠ·ΠΈΡΠΈΡ 3</div> </div> <div class="container"> <div class="component sc-data"> <table> <thead> <tr> <th>ΠΠ°ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½ΠΈΠ΅</th> </tr> </thead> <tbody> <tr id="sc-position1"> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr id="sc-position2"> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr> <td>test</td> </tr> <tr id="sc-position3"> <td>test</td> </tr> </tbody> </table> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>