From b1d5c27d522d8bf5248cb39dcc9b2907dd1c52ac Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Apr 2019 14:15:30 +0800 Subject: [PATCH 1/2] fix page content jump --- src/Drawer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Drawer.js b/src/Drawer.js index 6e05a1b0..ad277b53 100644 --- a/src/Drawer.js +++ b/src/Drawer.js @@ -297,12 +297,12 @@ class Drawer extends React.PureComponent { let widthTransition = `width ${duration} ${ease}`; const transformTransition = `transform ${duration} ${ease}`; if (open && document.body.style.overflow !== 'hidden') { - if (showMask) { - document.body.style.overflow = 'hidden'; - } if (right) { document.body.style.position = 'relative'; - document.body.style.width = `calc(100% - ${right}px)`; + if (showMask) { + document.body.style.overflow = 'hidden'; + document.body.style.width = `calc(100% - ${right}px)`; + } this.dom.style.transition = 'none'; switch (placement) { case 'right': From 2da9fd0b6724f9080a12f45e66c2c9eaa7b71ed9 Mon Sep 17 00:00:00 2001 From: jljsj Date: Mon, 29 Apr 2019 10:57:46 +0800 Subject: [PATCH 2/2] fix no showMask flash --- src/Drawer.js | 58 +++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/src/Drawer.js b/src/Drawer.js index ad277b53..0fc130fc 100644 --- a/src/Drawer.js +++ b/src/Drawer.js @@ -285,7 +285,7 @@ class Drawer extends React.PureComponent { } }); // 处理 body 滚动 - if (getContainer === 'body') { + if (getContainer === 'body' && showMask) { const eventArray = ['touchstart']; const domArray = [document.body, this.maskDom, this.handlerDom, this.contentDom]; const right = @@ -297,12 +297,10 @@ class Drawer extends React.PureComponent { let widthTransition = `width ${duration} ${ease}`; const transformTransition = `transform ${duration} ${ease}`; if (open && document.body.style.overflow !== 'hidden') { + document.body.style.overflow = 'hidden'; if (right) { document.body.style.position = 'relative'; - if (showMask) { - document.body.style.overflow = 'hidden'; - document.body.style.width = `calc(100% - ${right}px)`; - } + document.body.style.width = `calc(100% - ${right}px)`; this.dom.style.transition = 'none'; switch (placement) { case 'right': @@ -325,20 +323,18 @@ class Drawer extends React.PureComponent { this.dom.style.msTransform = ''; }); } - if (showMask) { - // 手机禁滚 - domArray.forEach((item, i) => { - if (!item) { - return; - } - addEventListener( - item, - eventArray[i] || 'touchmove', - i ? this.removeMoveHandler : this.removeStartHandler, - this.passive, - ); - }); - } + // 手机禁滚 + domArray.forEach((item, i) => { + if (!item) { + return; + } + addEventListener( + item, + eventArray[i] || 'touchmove', + i ? this.removeMoveHandler : this.removeStartHandler, + this.passive, + ); + }); } else if (this.getCurrentDrawerSome()) { document.body.style.overflow = ''; if ((this.isOpenChange || openTransition) && right) { @@ -383,19 +379,17 @@ class Drawer extends React.PureComponent { this.dom.style.height = ''; }); } - if (showMask) { - domArray.forEach((item, i) => { - if (!item) { - return; - } - removeEventListener( - item, - eventArray[i] || 'touchmove', - i ? this.removeMoveHandler : this.removeStartHandler, - this.passive, - ); - }); - } + domArray.forEach((item, i) => { + if (!item) { + return; + } + removeEventListener( + item, + eventArray[i] || 'touchmove', + i ? this.removeMoveHandler : this.removeStartHandler, + this.passive, + ); + }); } } }