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

文本特别长的话会截断 #6

Open
fengsx opened this issue Jan 19, 2018 · 1 comment
Open

文本特别长的话会截断 #6

fengsx opened this issue Jan 19, 2018 · 1 comment

Comments

@fengsx
Copy link

fengsx commented Jan 19, 2018

建议做下长度对比,比如是个外国人,如 弗拉基米尔·弗拉基米罗维奇·普京(普京) 001234,超过了 width 就截断了。

      const div = document.createElement('div');
      div.style.color = '#fff';
      div.style.fontSize = '14px';
      div.innerHTML = `<span>${text}</span>`;
      document.body.appendChild(div);

      const width = div.getElementsByTagName('span')[0].offsetWidth;

      div.parentNode.removeChild(div)
@hustcc
Copy link
Owner

hustcc commented Jan 19, 2018

感谢反馈,有兴趣提一个 pr 吗?

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

2 participants