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

HTMLElement.offset* by getBoundingClientRect() #21788

Merged
merged 3 commits into from
Mar 19, 2017
Merged

Conversation

pvdlg
Copy link
Contributor

@pvdlg pvdlg commented Jan 20, 2017

Fixes #19774.

@@ -133,7 +133,7 @@ const ScrollSpy = (($) => {
target = $(targetSelector)[0]
}

if (target && (target.offsetWidth || target.offsetHeight)) {
if (target && (target.getBoundingClientRect().width || target.getBoundingClientRect().height)) {
Copy link
Member

@Johann-S Johann-S Jan 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how works the logic of getBoundingClientRect but you can declare variable to just have one call to getBoundingClientRect instead of two

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is what I did at the beginning, but I have to check if target is non null, so the code would have been:

if (target) {
  const targetBCR = target.getBoundingClientRect()
  if (target.targetBCR.width || targetBCR.height) {
   //Do something
  }
}

So that makes longer code and less legible IMO. That said, I don't know if the browser has to compute the result for each call or if it just return a result that was already there.
I'll do some research quickly to check and I'll change the code accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found something about the algorithm if it can help you : https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the chance. Thanks !

@bardiharborow bardiharborow added this to the v4.0.0-beta milestone Jan 21, 2017
@mdo mdo merged commit 275821b into twbs:v4-dev Mar 19, 2017
This was referenced Mar 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants