iframe多页签下滚动条宽度计算有问题

This commit is contained in:
wanghaoo 2018-11-29 18:53:07 +08:00
parent 373a6fef2f
commit e2481f75ff
6 changed files with 55 additions and 41 deletions

View File

@ -775,7 +775,7 @@ var Table = function (_Component) {
useFixedHeader = true; useFixedHeader = true;
// Add negative margin bottom for scroll bar overflow bug // Add negative margin bottom for scroll bar overflow bug
var scrollbarWidth = this.scrollbarWidth; var scrollbarWidth = this.scrollbarWidth ? this.scrollbarWidth : 15;
if (scrollbarWidth >= 0) { if (scrollbarWidth >= 0) {
(fixed ? bodyStyle : headStyle).paddingBottom = '0px'; (fixed ? bodyStyle : headStyle).paddingBottom = '0px';
//显示表头滚动条 //显示表头滚动条

View File

@ -27,7 +27,7 @@ var _parseInt2 = _interopRequireDefault(_parseInt);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var scrollbarWidth = void 0; var scrollbarSize = void 0;
// Measure scrollbar width for padding body during modal show/hide // Measure scrollbar width for padding body during modal show/hide
var scrollbarMeasure = { var scrollbarMeasure = {
@ -39,24 +39,29 @@ var scrollbarMeasure = {
}; };
function measureScrollbar() { function measureScrollbar() {
var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'vertical';
if (typeof document === 'undefined' || typeof window === 'undefined') { if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0; return 0;
} }
if (window.scrollbarWidth) { if (scrollbarSize) {
return window.scrollbarWidth; return scrollbarSize;
} }
var scrollDiv = document.createElement('div'); var scrollDiv = document.createElement('div');
for (var scrollProp in scrollbarMeasure) { Object.keys(scrollbarMeasure).forEach(function (scrollProp) {
if (scrollbarMeasure.hasOwnProperty(scrollProp)) { scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp]; });
}
}
document.body.appendChild(scrollDiv); document.body.appendChild(scrollDiv);
var width = scrollDiv.offsetWidth - scrollDiv.clientWidth; var size = 0;
if (direction === 'vertical') {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
} else if (direction === 'horizontal') {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
}
document.body.removeChild(scrollDiv); document.body.removeChild(scrollDiv);
scrollbarWidth = width; scrollbarSize = size;
window.scrollbarWidth = scrollbarWidth; return scrollbarSize;
return scrollbarWidth;
} }
function debounce(func, wait, immediate) { function debounce(func, wait, immediate) {

31
dist/demo.js vendored
View File

@ -11343,7 +11343,7 @@
useFixedHeader = true; useFixedHeader = true;
// Add negative margin bottom for scroll bar overflow bug // Add negative margin bottom for scroll bar overflow bug
var scrollbarWidth = this.scrollbarWidth; var scrollbarWidth = (0, _utils.measureScrollbar)();
if (scrollbarWidth >= 0) { if (scrollbarWidth >= 0) {
(fixed ? bodyStyle : headStyle).paddingBottom = '0px'; (fixed ? bodyStyle : headStyle).paddingBottom = '0px';
//显示表头滚动条 //显示表头滚动条
@ -13378,7 +13378,7 @@
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var scrollbarWidth = void 0; var scrollbarSize = void 0;
// Measure scrollbar width for padding body during modal show/hide // Measure scrollbar width for padding body during modal show/hide
var scrollbarMeasure = { var scrollbarMeasure = {
@ -13390,24 +13390,29 @@
}; };
function measureScrollbar() { function measureScrollbar() {
var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'vertical';
if (typeof document === 'undefined' || typeof window === 'undefined') { if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0; return 0;
} }
if (window.scrollbarWidth) { if (scrollbarSize) {
return window.scrollbarWidth; return scrollbarSize;
} }
var scrollDiv = document.createElement('div'); var scrollDiv = document.createElement('div');
for (var scrollProp in scrollbarMeasure) { Object.keys(scrollbarMeasure).forEach(function (scrollProp) {
if (scrollbarMeasure.hasOwnProperty(scrollProp)) { scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp]; });
}
}
document.body.appendChild(scrollDiv); document.body.appendChild(scrollDiv);
var width = scrollDiv.offsetWidth - scrollDiv.clientWidth; var size = 0;
if (direction === 'vertical') {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
} else if (direction === 'horizontal') {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
}
document.body.removeChild(scrollDiv); document.body.removeChild(scrollDiv);
scrollbarWidth = width; scrollbarSize = size;
window.scrollbarWidth = scrollbarWidth; return scrollbarSize;
return scrollbarWidth;
} }
function debounce(func, wait, immediate) { function debounce(func, wait, immediate) {

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -675,7 +675,7 @@ class Table extends Component {
useFixedHeader = true; useFixedHeader = true;
// Add negative margin bottom for scroll bar overflow bug // Add negative margin bottom for scroll bar overflow bug
const scrollbarWidth = this.scrollbarWidth; const scrollbarWidth = this.scrollbarWidth ?this.scrollbarWidth: 15;
if (scrollbarWidth >= 0) { if (scrollbarWidth >= 0) {
(fixed ? bodyStyle : headStyle).paddingBottom = '0px'; (fixed ? bodyStyle : headStyle).paddingBottom = '0px';
//显示表头滚动条 //显示表头滚动条

View File

@ -2,7 +2,7 @@ import warning from 'warning';
import parseInt from 'lodash/parseInt'; import parseInt from 'lodash/parseInt';
let scrollbarWidth; let scrollbarSize;
// Measure scrollbar width for padding body during modal show/hide // Measure scrollbar width for padding body during modal show/hide
const scrollbarMeasure = { const scrollbarMeasure = {
@ -13,27 +13,31 @@ const scrollbarMeasure = {
overflow: 'scroll', overflow: 'scroll',
}; };
export function measureScrollbar() { export function measureScrollbar(direction = 'vertical') {
if (typeof document === 'undefined' || typeof window === 'undefined') { if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0; return 0;
} }
if (window.scrollbarWidth) { if (scrollbarSize) {
return window.scrollbarWidth; return scrollbarSize;
} }
const scrollDiv = document.createElement('div'); const scrollDiv = document.createElement('div');
for (const scrollProp in scrollbarMeasure) { Object.keys(scrollbarMeasure).forEach(scrollProp => {
if (scrollbarMeasure.hasOwnProperty(scrollProp)) { scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp]; });
}
}
document.body.appendChild(scrollDiv); document.body.appendChild(scrollDiv);
const width = scrollDiv.offsetWidth - scrollDiv.clientWidth; let size = 0;
if (direction === 'vertical') {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
} else if (direction === 'horizontal') {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
}
document.body.removeChild(scrollDiv); document.body.removeChild(scrollDiv);
scrollbarWidth = width; scrollbarSize = size;
window.scrollbarWidth = scrollbarWidth; return scrollbarSize;
return scrollbarWidth;
} }
export function debounce(func, wait, immediate) { export function debounce(func, wait, immediate) {
let timeout; let timeout;
return function debounceFunc() { return function debounceFunc() {