davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.

Home Page:https://iframe-resizer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: add optional offset argument to moveToAnchor method

JayEn84 opened this issue · comments

commented

We use the moveToAnchor method to scroll to a specific target within the iFrame. Works like a charm.
Now we have a parent site that has a fixed header with a height of approx. 50px. When using the moveToAnchor method, the target is directly behind the fixed header.

An optional offset argument in the moveToAnchorMethod would be an easy way to take fixed headers into account.

You can sort of already do this via the onScroll event on the parent page.

https://github.com/davidjbradshaw/iframe-resizer/blob/master/docs/parent_page/events.md#onscroll

   onScroll: ({x, y}) => {
      window.scroll(x, y - 50)
      return false
   }
commented

Yes, that's a possible solution. What we do instead is this:

parentIFrame.scrollToOffset(0, anchorScrollTop - 60);

However, I think the optional argument would make it a little easier, which is why I thought I'd provide you with the suggestion over here. :)

Guess it might be nice to be able to return updated x, y values here, rather than have to implement it yourself to get the offset.

  onScroll: ({x, y}) => { x, y: y -50 }

Happy to take a PR if you want to make one to do this.

I’m trying not to add more options, as this is already complex enough. But a new return type to an event would have less impact on the API surface.