Skip to content

Conversation

@el-fuego
Copy link
Contributor

When you are using of non-integer values for the sizes, offsetWidth can be differ per each element in a list

// What was used
$$('.item').map(i => i.offsetWidth)
(8) [199, 200, 199, 199, 199, 200, 199, 199]

// Computed css styles
$$('.item').map(i => i.style.width)
(8) ["199.5px", "199.5px", "199.5px", "199.5px", "199.5px", "199.5px", "199.5px", "199.5px"]

// BoundingClientRect
$$('.item').map(i => i.getBoundingClientRect().width)
(8) [199.5, 199.5, 199.5, 199.5, 199.5, 199.5, 199.5, 199.5]

Compatibility: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

@marcj
Copy link
Owner

marcj commented Dec 22, 2017

Do you know why the browser engine sometimes returns 199 and sometimes 200 in offsetWidth for a value of 199.5?

@el-fuego
Copy link
Contributor Author

Probably, a bug or trying of use the same summ result as the container offsetWidth

@marcj marcj merged commit 072a3fc into marcj:master Dec 22, 2017
@marcj
Copy link
Owner

marcj commented Dec 22, 2017

Ok cool, thanks!

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

Successfully merging this pull request may close these issues.

2 participants