@@ -256,6 +256,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
256
256
var lastParentOverFlow ;
257
257
var backdrop ;
258
258
var triggeringElement = null ;
259
+ var previousContainerStyles ;
259
260
var promise = $q . when ( true ) ;
260
261
var isLockedOpenParsed = $parse ( attr . mdIsLockedOpen ) ;
261
262
var isLocked = function ( ) {
@@ -324,6 +325,8 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
324
325
parent [ isOpen ? 'on' : 'off' ] ( 'keydown' , onKeyDown ) ;
325
326
if ( backdrop ) backdrop [ isOpen ? 'on' : 'off' ] ( 'click' , close ) ;
326
327
328
+ var restorePositioning = updateContainerPositions ( parent , isOpen ) ;
329
+
327
330
if ( isOpen ) {
328
331
// Capture upon opening..
329
332
triggeringElement = $document [ 0 ] . activeElement ;
@@ -332,16 +335,60 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
332
335
disableParentScroll ( isOpen ) ;
333
336
334
337
return promise = $q . all ( [
335
- isOpen && backdrop ? $animate . enter ( backdrop , parent ) :
336
- backdrop ? $animate . leave ( backdrop ) : $q . when ( true ) ,
337
- $animate [ isOpen ? 'removeClass' : 'addClass' ] ( element , '_md-closed' )
338
- ] )
339
- . then ( function ( ) {
340
- // Perform focus when animations are ALL done...
341
- if ( scope . isOpen ) {
342
- focusEl && focusEl . focus ( ) ;
343
- }
344
- } ) ;
338
+ isOpen && backdrop ? $animate . enter ( backdrop , parent ) : backdrop ?
339
+ $animate . leave ( backdrop ) : $q . when ( true ) ,
340
+ $animate [ isOpen ? 'removeClass' : 'addClass' ] ( element , '_md-closed' )
341
+ ] ) . then ( function ( ) {
342
+ // Perform focus when animations are ALL done...
343
+ if ( scope . isOpen ) {
344
+ focusEl && focusEl . focus ( ) ;
345
+ }
346
+
347
+ // Restores the positioning on the sidenav and backdrop.
348
+ restorePositioning && restorePositioning ( ) ;
349
+ } ) ;
350
+ }
351
+
352
+ function updateContainerPositions ( parent , willOpen ) {
353
+ var drawerEl = element [ 0 ] ;
354
+ var scrollTop = parent [ 0 ] . scrollTop ;
355
+
356
+ if ( willOpen && scrollTop ) {
357
+ previousContainerStyles = {
358
+ top : drawerEl . style . top ,
359
+ bottom : drawerEl . style . bottom ,
360
+ height : drawerEl . style . height
361
+ } ;
362
+
363
+ // When the parent is scrolled down, then we want to be able to show the sidenav at the current scroll
364
+ // position. We're moving the sidenav down to the correct scroll position and apply the height of the
365
+ // parent, to increase the performance. Using 100% as height, will impact the performance heavily.
366
+ var positionStyle = {
367
+ top : scrollTop + 'px' ,
368
+ bottom : 'initial' ,
369
+ height : parent [ 0 ] . clientHeight + 'px'
370
+ } ;
371
+
372
+ // Apply the new position styles to the sidenav and backdrop.
373
+ element . css ( positionStyle ) ;
374
+ backdrop . css ( positionStyle ) ;
375
+ }
376
+
377
+ // When the sidenav is closing and we have previous defined container styles,
378
+ // then we return a restore function, which resets the sidenav and backdrop.
379
+ if ( ! willOpen && previousContainerStyles ) {
380
+ return function ( ) {
381
+ drawerEl . style . top = previousContainerStyles . top ;
382
+ drawerEl . style . bottom = previousContainerStyles . bottom ;
383
+ drawerEl . style . height = previousContainerStyles . height ;
384
+
385
+ backdrop [ 0 ] . style . top = null ;
386
+ backdrop [ 0 ] . style . bottom = null ;
387
+ backdrop [ 0 ] . style . height = null ;
388
+
389
+ previousContainerStyles = null ;
390
+ }
391
+ }
345
392
}
346
393
347
394
/**
0 commit comments