Fractional scrollHeight?

2019-02-17 06:54发布

https://developer.mozilla.org/en-US/docs/Web/API/element.scrollHeight:

This property will round the value to an integer. If you need a fractional value, use element.getBoundingClientRect().

Except... element.getBoundingClientRect() does not return the scrollHeight. How would one get a fractional scrollHeight? Is it possible?

1条回答
做自己的国王
2楼-- · 2019-02-17 07:28

I think I might have the solution:

var rect = element.getBoundingClientRect()
var scrollHeight = element.scrollHeight + (parseInt(rect.height) - rect.height)
var scrollWidth  = element.scrollWidth  + (parseInt(rect.width)  - rect.width)
查看更多
登录 后发表回答