Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table 中如何修改scrollbarwidth的宽度, #1125

Open
christingliu opened this issue May 15, 2024 · 0 comments
Open

Table 中如何修改scrollbarwidth的宽度, #1125

christingliu opened this issue May 15, 2024 · 0 comments

Comments

@christingliu
Copy link

christingliu commented May 15, 2024

Description

设置fixed固定列,但是想要调整全局的滚动条展示宽度和高度,getScrollBarWidth 方法
let scrollBarWidth: ?number;

export function getScrollBarWidth(): ?number {
if (scrollBarWidth !== undefined) return scrollBarWidth;
const dom = _document.createElement('div');
const body = _document.body || dom;

dom.style.visibility = 'hidden';
dom.style.width = '100px';
dom.style.position = 'absolute';
dom.style.top = '-9999px';
dom.style.overflow = 'scroll';

body.appendChild(dom);

const totalWidth = dom.offsetWidth;
const widthWithoutScroll = dom.clientWidth;

body.removeChild(dom);

return totalWidth - widthWithoutScroll;
}

Reproduce Steps

  1. [First Step]
  2. [Second Step]
  3. [and so on...]

Error Trace (if possible)

scrollBarWidth 这个宽度虽然定义了变量,但是在代码里未找到赋值这个变量的地方。那if的判断是不是没有用那。

Solution

同样的问题在elementUI,vue框架里面的方法
import Vue from 'vue';

let scrollBarWidth;

export default function() {
if (Vue.prototype.$isServer) return 0;
if (scrollBarWidth !== undefined) return scrollBarWidth;

const outer = document.createElement('div');
outer.className = 'el-scrollbar__wrap';
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.position = 'absolute';
outer.style.top = '-9999px';
document.body.appendChild(outer);

const widthNoScroll = outer.offsetWidth;
outer.style.overflow = 'scroll';

const inner = document.createElement('div');
inner.style.width = '100%';
outer.appendChild(inner);

const widthWithScroll = inner.offsetWidth;
outer.parentNode.removeChild(outer);
scrollBarWidth = widthNoScroll - widthWithScroll;

return scrollBarWidth;
};
区别在于加入了一个className='el-scrollbar__wrap'。element-react里是否也可以添加上这样一个类名。这样可以方便外层调整element-table的fix 固定列滚动条的宽度。

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant