@@ -2339,6 +2339,14 @@ angular.module('ui.grid')
23392339 return this . hasRightContainer ( ) && this . renderContainers . right . renderedColumns . length > 0 ;
23402340 } ;
23412341
2342+ // Turn the scroll position into a percentage and make it an argument for a scroll event
2343+ function getScrollPercentage ( scrollPixels , scrollLength ) {
2344+ var percentage = scrollPixels / scrollLength ;
2345+
2346+ // if the percentage is greater than 1, set it to 1
2347+ return percentage <= 1 ? percentage : 1 ;
2348+ }
2349+
23422350 /**
23432351 * @ngdoc method
23442352 * @methodOf ui.grid.class:Grid
@@ -2405,31 +2413,23 @@ angular.module('ui.grid')
24052413 // Don't let the pixels required to see the row be less than zero
24062414 pixelsToSeeRow = ( pixelsToSeeRow < 0 ) ? 0 : pixelsToSeeRow ;
24072415
2408- var scrollPixels , percentage ;
2416+ var scrollPixels ;
24092417
24102418 // If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
24112419 if ( pixelsToSeeRow < topBound ) {
24122420 // Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
24132421 // to get the full position we need
24142422 scrollPixels = self . renderContainers . body . prevScrollTop - ( topBound - pixelsToSeeRow ) ;
24152423
2416- // Turn the scroll position into a percentage and make it an argument for a scroll event
2417- percentage = scrollPixels / scrollLength ;
2418- if ( percentage <= 1 ) {
2419- scrollEvent . y = { percentage : percentage } ;
2420- }
2424+ scrollEvent . y = { percentage : getScrollPercentage ( scrollPixels , scrollLength ) } ;
24212425 }
24222426 // Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
24232427 else if ( pixelsToSeeRow > bottomBound ) {
24242428 // Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
24252429 // to get the full position we need
24262430 scrollPixels = pixelsToSeeRow - bottomBound + self . renderContainers . body . prevScrollTop ;
24272431
2428- // Turn the scroll position into a percentage and make it an argument for a scroll event
2429- percentage = scrollPixels / scrollLength ;
2430- if ( percentage <= 1 ) {
2431- scrollEvent . y = { percentage : percentage } ;
2432- }
2432+ scrollEvent . y = { percentage : getScrollPercentage ( scrollPixels , scrollLength ) } ;
24332433 }
24342434 }
24352435
0 commit comments