mirror of
https://github.com/DataTables/DataTables.git
synced 2024-12-10 22:24:10 +01:00
Performance: Width of scrollbars isn't going to change on a single page
between table's being reinitialised, so calculating the scrollbar width every time is a real hit on performance since it needs to manipulate the DOM. This change ensures that the calculation is performed only once.
This commit is contained in:
parent
182998a7c5
commit
ad0e08585f
@ -378,36 +378,41 @@ function _fnStringToCss( s )
|
|||||||
*/
|
*/
|
||||||
function _fnScrollBarWidth ()
|
function _fnScrollBarWidth ()
|
||||||
{
|
{
|
||||||
var inner = $('<p/>').css( {
|
if ( ! DataTable.__scrollbarWidth )
|
||||||
width: '100%',
|
|
||||||
height: 200,
|
|
||||||
padding: 0
|
|
||||||
} )[0];
|
|
||||||
|
|
||||||
var outer = $('<div/>')
|
|
||||||
.css( {
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
width: 200,
|
|
||||||
height: 150,
|
|
||||||
padding: 0,
|
|
||||||
overflow: 'hidden',
|
|
||||||
visibility: 'hidden'
|
|
||||||
} )
|
|
||||||
.append( inner )
|
|
||||||
.appendTo( 'body' );
|
|
||||||
|
|
||||||
var w1 = inner.offsetWidth;
|
|
||||||
outer.css( 'overflow', 'scroll' );
|
|
||||||
var w2 = inner.offsetWidth;
|
|
||||||
if ( w1 === w2 )
|
|
||||||
{
|
{
|
||||||
w2 = outer[0].clientWidth;
|
var inner = $('<p/>').css( {
|
||||||
|
width: '100%',
|
||||||
|
height: 200,
|
||||||
|
padding: 0
|
||||||
|
} )[0];
|
||||||
|
|
||||||
|
var outer = $('<div/>')
|
||||||
|
.css( {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: 200,
|
||||||
|
height: 150,
|
||||||
|
padding: 0,
|
||||||
|
overflow: 'hidden',
|
||||||
|
visibility: 'hidden'
|
||||||
|
} )
|
||||||
|
.append( inner )
|
||||||
|
.appendTo( 'body' );
|
||||||
|
|
||||||
|
var w1 = inner.offsetWidth;
|
||||||
|
outer.css( 'overflow', 'scroll' );
|
||||||
|
var w2 = inner.offsetWidth;
|
||||||
|
if ( w1 === w2 )
|
||||||
|
{
|
||||||
|
w2 = outer[0].clientWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
outer.remove();
|
||||||
|
|
||||||
|
DataTable.__scrollbarWidth = w1 - w2;
|
||||||
}
|
}
|
||||||
|
|
||||||
outer.remove();
|
return DataTable.__scrollbarWidth;
|
||||||
|
|
||||||
return w1 - w2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user