Skip to content

Commit

Permalink
Make the top and bottom of the scrolling area, when virtual scrolling…
Browse files Browse the repository at this point in the history
…, linear for a better interface
  • Loading branch information
Allan Jardine committed Jul 28, 2018
1 parent 2f55821 commit 58f0bbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/initialisation/server-side_processing.xml
Expand Up @@ -29,7 +29,7 @@ $(document).ready(function() {
scroller: { scroller: {
loadingIndicator: true loadingIndicator: true
}, },
stateSave: true //stateSave: true
} ); } );
} ); } );
]]> ]]>
Expand Down
15 changes: 13 additions & 2 deletions js/dataTables.scroller.js
Expand Up @@ -789,15 +789,26 @@ $.extend( Scroller.prototype, {
return val; return val;
} }


// In the first 10k pixels and the last 10k pixels, we want the scrolling
// to be linear. After that it can be non-linear. It would be unusual for
// anyone to mouse wheel through that much.
if ( val < 10000 ) {
return val;
}
else if ( val > heights.scroll - 10000 ) {
var diff = heights.scroll - val;
return heights.virtual - diff;
}

// Otherwise, we want a non-linear scrollbar to take account of the // Otherwise, we want a non-linear scrollbar to take account of the
// redrawing regions at the start and end of the table, otherwise these // redrawing regions at the start and end of the table, otherwise these
// can stutter badly - on large tables 30px (for example) scroll might // can stutter badly - on large tables 30px (for example) scroll might
// be hundreds of rows, so the table would be redrawing every few px at // be hundreds of rows, so the table would be redrawing every few px at
// the start and end. Use a simple quadratic to stop this. It does mean // the start and end. Use a simple quadratic to stop this. It does mean
// the scrollbar is non-linear, but with such massive data sets, the // the scrollbar is non-linear, but with such massive data sets, the
// scrollbar is going to be a best guess anyway // scrollbar is going to be a best guess anyway
var xMax = (heights.scroll - heights.viewport) / 2; var xMax = (heights.scroll - heights.viewport - 10000) / 2;
var yMax = (heights.virtual - heights.viewport) / 2; var yMax = (heights.virtual - heights.viewport - 10000) / 2;


coeff = yMax / ( xMax * xMax ); coeff = yMax / ( xMax * xMax );


Expand Down

0 comments on commit 58f0bbc

Please sign in to comment.