0

I had this working in angular.js but I can't figure out how to convert it to Angular 8. I need to locate the first 'iframe' in the DOM and scroll to the top of it on a button click that triggers this scrollToTop() function.

scrollToTop() {
    //need to scroll on body and html elements due to browser differences
    let editorBody = this.$document.find('iframe')[0].contentDocument.body;
    let editorHtml = this.$document.find('iframe')[0].contentDocument.documentElement;
    angular.element(editorBody).duScrollTop(0);
    angular.element(editorHtml).duScrollTop(0);
  }

1 Answer 1

1

This can be done with vanilla JavaScript. You can use querySelector() to get the first Element which matches the specific selector (iframe). Then. you can use scrollIntoView to scroll to that specific position.

document.querySelector('iframe').scrollIntoView(true);

I have created a demo over here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.