Workaround for issue with IE scrollWidth

后端 未结 3 1709
死守一世寂寞
死守一世寂寞 2021-02-07 08:44

I seem to have stumbled onto a bug in IE where the scrollWidth is off by 1px compared to the offsetWidth. The trigger to this seems to be dependent on the length of the text/ch

3条回答
  •  囚心锁ツ
    2021-02-07 09:32

    It's hard to give the best solution without knowing how this applies to your specific problem with this bug. That being said, you could:

    • Use a javascript bug-fix to adjust the attributes/styles/etc. if the two elements are different sizes.

      if(iDifference != 0) { /* make adjustments. */ }

    • Use a tolerance check between the two elements; if the difference is less than or equal to 2px, then don't worry about it and process everything as normal.

      if(Math.abs(iDifference) <= 2) { /* no problem here! */ }

    • Use the outer element for all computations, since that has the true width of the container.

    • Use the inner element for all computations, since that will never cause an overlap with the outer element.

    • Do nothing! Why fix it if it isn't broken?

    It all depends on what you're trying to do and how the 1px gap is causing a problem.

提交回复
热议问题