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

Can't make scrollbar follow new content added to overflow bottom. #901

Closed
RadiactoR opened this issue Oct 25, 2023 · 7 comments
Closed

Can't make scrollbar follow new content added to overflow bottom. #901

RadiactoR opened this issue Oct 25, 2023 · 7 comments

Comments

@RadiactoR
Copy link

Since this is traditionally worked around using JavaScript, and there isn't any css property for it, there's currently no way (that I could find) to make an element's overflowing content make the scrollbar follow the newest content getting added at the bottom. For example, I have an element that is displaying live .log files, but as the div fills up, the scroll stays at the top of the list.

Is this an issue with go-app, or am I missing something?

@RadiactoR RadiactoR changed the title Can't make scrollbar follow new content added to element. Can't make scrollbar follow new content added to overflow bottom. Oct 25, 2023
@oderwat
Copy link
Sponsor Contributor

oderwat commented Oct 25, 2023

Just use your JavaScript (call it from your go code) or write similar code using the JS interoperation (app.Window())

@RadiactoR
Copy link
Author

The second option is the only one I can work with atm, what would an "app.Window()" line manipulating elements look like?

@oderwat
Copy link
Sponsor Contributor

oderwat commented Oct 25, 2023

I am very busy right now. I think I can show you some code later.

@RadiactoR
Copy link
Author

That would be great, thx.

@oderwat
Copy link
Sponsor Contributor

oderwat commented Oct 25, 2023

Here some code fragment that shows similar stuff. I think you need "block" "end" with the target of the div you want to scroll. You could also set scroll top to the height (using el.Get('height') or something like that.

		if newURL.Fragment != "" {
			target := app.Window().Get("document").Call("querySelector", "a[name='"+newURL.Fragment+"']")
			if target.Truthy() {
				opts := map[string]interface{}{ /*"behavior": "smooth",*/ "block": "start"}
				target.Call("scrollIntoView", opts)
			}
		} else {
			pc := app.Window().GetElementByID("pagecontent")
			if pc.Truthy() {
				pc.Set("scrollTop", 0)
			}
		}

@RadiactoR
Copy link
Author

Thank you, but I actually solved it myself earlier today. I called "app.Script().Text()" and inside of Text() I wrote some simple JS code. Wish there would be a simpler way to interact with JS comands.

@oderwat
Copy link
Sponsor Contributor

oderwat commented Oct 26, 2023

@RadiactoR I think it is pretty simple to handle JS, it is more that the interfacing code is not that great, so we end up writing JavaScript and call it from Go at times. Emitting script from the renderer would not be my way to handle stuff. I think this is prone to edge cases, because of how the DOM is compared and updated with what you "Render()". But if it works like that, it is probably good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants