Added ScrollIntoViewIfNeeded function

This commit is contained in:
Alexei Anoshenko 2026-04-16 17:50:53 +03:00
parent 991f87e4b1
commit 6c84f332aa
3 changed files with 23 additions and 1 deletions

View File

@ -2,7 +2,7 @@
* Removed "style-disabled" property and GetDisabledStyle function * Removed "style-disabled" property and GetDisabledStyle function
* Added GoogleFonts field to AppParams * Added GoogleFonts field to AppParams
* Added functions: GetWhiteSpace, GetWordBreak * Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded
# v0.20.0 # v0.20.0

View File

@ -1280,6 +1280,17 @@ function scrollToEnd(elementId) {
} }
} }
function scrollIntoViewIfNeeded(elementId) {
const element = document.getElementById(elementId);
if (element) {
if (element.scrollIntoViewIfNeeded) {
element.scrollIntoViewIfNeeded()
} else {
element.scrollIntoView({block: "nearest", inline: "nearest"});
}
}
}
function focus(elementId) { function focus(elementId) {
const element = document.getElementById(elementId); const element = document.getElementById(elementId);
if (element) { if (element) {

View File

@ -100,3 +100,14 @@ func ScrollViewToEnd(view View, subviewID ...string) {
view.Session().callFunc("scrollToEnd", view.htmlID()) view.Session().callFunc("scrollToEnd", view.htmlID())
} }
} }
// ScrollIntoViewIfNeeded scrolls the current view into the visible area of the browser window if it's not already within the visible area of the browser window.
// If the element is already within the visible area of the browser window, then no scrolling takes place.
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
func ScrollIntoViewIfNeeded(view View, subviewID ...string) {
if view = getSubview(view, subviewID); view != nil {
view.Session().callFunc("scrollIntoViewIfNeeded", view.htmlID())
}
}