mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 13:01:01 +08:00
fix(backdrop): use raf when adding/removing disable-scroll css
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
import {Directive, ViewEncapsulation, HostListener, ElementRef, Input} from '@angular/core';
|
import { Directive, ElementRef, Input } from '@angular/core';
|
||||||
|
|
||||||
import { isTrueProperty} from '../../util/util';
|
import { isTrueProperty} from '../../util/util';
|
||||||
|
import { nativeRaf} from '../../util/dom';
|
||||||
|
|
||||||
const DISABLE_SCROLL = 'disable-scroll';
|
const DISABLE_SCROLL = 'disable-scroll';
|
||||||
|
|
||||||
@ -19,23 +21,24 @@ export class Backdrop {
|
|||||||
|
|
||||||
private static push() {
|
private static push() {
|
||||||
if (this.nuBackDrops === 0) {
|
if (this.nuBackDrops === 0) {
|
||||||
|
nativeRaf(() => {
|
||||||
console.debug('adding .disable-scroll to body');
|
console.debug('adding .disable-scroll to body');
|
||||||
document.body.classList.add(DISABLE_SCROLL);
|
document.body.classList.add(DISABLE_SCROLL);
|
||||||
} else {
|
});
|
||||||
console.warn('several backdrops on screen? probably a bug');
|
|
||||||
}
|
}
|
||||||
this.nuBackDrops++;
|
this.nuBackDrops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static pop() {
|
private static pop() {
|
||||||
if (this.nuBackDrops === 0) {
|
if (this.nuBackDrops > 0) {
|
||||||
console.error('pop requires a push');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.nuBackDrops--;
|
this.nuBackDrops--;
|
||||||
|
|
||||||
if (this.nuBackDrops === 0) {
|
if (this.nuBackDrops === 0) {
|
||||||
|
nativeRaf(() => {
|
||||||
console.debug('removing .disable-scroll from body');
|
console.debug('removing .disable-scroll from body');
|
||||||
document.body.classList.remove(DISABLE_SCROLL);
|
document.body.classList.remove(DISABLE_SCROLL);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user