Advertisement
DataCCIW

Top Scroll Bar Hack

Aug 13th, 2022
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.17 KB | None | 0 0
  1. <div id="topScroller" style="height: 20px; overflow-x: scroll;display:none">
  2.     <div id="gridTableMirror" style="height: 20px;"></div>
  3. </div>
  4.  
  5. {% javascript %}
  6.     $().ready(function () {
  7.         // Set the width of the extra scroll bar we added and show the extra scroll bar if a bottom scroll bar exists
  8.  
  9.         var tableResponsiveWidth = $(".table-responsive").width();
  10.         var gridTableWidth  = $(".grid-table").width();
  11.  
  12.         // if these widths are the same then no scroll bar is necessary
  13.         if (tableResponsiveWidth != gridTableWidth) {
  14.             $("#topScroller").width(tableResponsiveWidth);
  15.             $("#gridTableMirror").width(gridTableWidth);
  16.             $("#topScroller").show();
  17.         }
  18.  
  19.     });
  20.  
  21.     // Per https://jsfiddle.net/TBnqw/1/
  22.     // tie our custom scroll bar at the top to the bottom scroll bar
  23.     $(function () {
  24.         $("#topScroller").scroll(function () {
  25.             $(".table-responsive").scrollLeft($("#topScroller").scrollLeft());
  26.         });
  27.         $(".table-responsive").scroll(function () {
  28.             $("#topScroller").scrollLeft($(".table-responsive").scrollLeft());
  29.         });
  30.     });
  31. {% endjavascript %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement