fix: reset the padding right of the body when sizing

Fixed #379
This commit is contained in:
Chen Fengyuan 2020-06-06 17:56:16 +08:00
parent 69836ea060
commit 2ad60bd6fe
4 changed files with 18 additions and 8 deletions

View File

@ -4,6 +4,7 @@
- Ignore images without the `src` attribute (#326).
- Improve the `hide` method for unexpected calling (#367).
- Reset the padding right of the `body` element when resizing (#379).
- Remove unnecessary `padding-right: 0px` from the `body` element when close the viewer modal (#394).
## 1.5.0 (Nov 23, 2019)

View File

@ -439,6 +439,12 @@ export default {
return;
}
if (this.fulled) {
this.close();
this.initBody();
this.open();
}
this.initContainer();
this.initViewer();
this.renderViewer();

View File

@ -29,6 +29,16 @@ export default {
this.renderViewer();
},
initBody() {
const { ownerDocument } = this.element;
const body = ownerDocument.body || ownerDocument.documentElement;
this.body = body;
this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
this.initialBodyPaddingRight = body.style.paddingRight;
this.initialBodyComputedPaddingRight = window.getComputedStyle(body).paddingRight;
},
initContainer() {
this.containerData = {
width: window.innerWidth,

View File

@ -104,14 +104,7 @@ class Viewer {
this.isImg = isImg;
this.length = images.length;
this.images = images;
const { ownerDocument } = element;
const body = ownerDocument.body || ownerDocument.documentElement;
this.body = body;
this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
this.initialBodyPaddingRight = body.style.paddingRight;
this.initialBodyComputedPaddingRight = window.getComputedStyle(body).paddingRight;
this.initBody();
// Override `transition` option if it is not supported
if (isUndefined(document.createElement(NAMESPACE).style.transition)) {