Vertical Scroll bar to move top of the page

Having trouble installing Oxygen? Got a bug to report? Post it all here.
shilpa
Posts: 66
Joined: Mon Jul 04, 2022 8:42 am

Vertical Scroll bar to move top of the page

Post by shilpa »

Hi Oxygen team,
I am working on web author mode and have added script in plugin window.scrollTo() to move vertical scroll bar to top of the page but its not working.
I would like to know what is the best way to move scroll to top of the page.
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: Vertical Scroll bar to move top of the page

Post by Gabriel Titerlea »

Hello,

You can scroll the document in different ways, depending on what you want to achieve.

If you want to scroll to a given xml-element you can use the SelectionManager.scrollSelectionIntoView javascript API [1]. Here's an example where I'm scrolling to the beginning of the root element:

Code: Select all

let selectionManager = editor.getSelectionManager();
let doc = editor.getEditingSupport().getDocument();

let selection = selectionManager.createEmptySelectionBeforeNode(doc.firstChild);
selectionManager.scrollSelectionIntoView(selection);
Alternatively, if you are not interested in scrolling to a certain xml-element. You can change the scrollTop [2] of the html-element with ID editor-frame. Note that this element ID is not marked as a public API, and it may change in future versions.

Best,
Gabriel

[1] https://www.oxygenxml.com/maven/com/oxy ... ew__anchor
[2] https://developer.mozilla.org/en-US/doc ... /scrollTop
Post Reply