Scrollto

Am I missing something or is there no webcontainer.scrollto anymore ?

Perhaps I should expand on this.

Pre Web 2.0, I could use scrollto to move to a particular position within a container which is useful when you have a list of containers within a container and you want to scroll to the bottom.

Frustrated !!

Thanks in advance for any help on this.

By the silence (and the LR WebContainer - Xojo Documentation) I assume you are correct that ‘there no webcontainer.scrollto’.

I’m in a meeting for another hour, then I’ll take a look if nobody else has. Should be some fairly simple JavaScript.

1 Like

Cheers Anthony.

Much Appreciated

Here are a few methods you can use. Add to a module and call as outlined in comments:

Public Sub scrollTo(extends c as WebContainer, X as Integer, Y as Integer)
  '// myContainer.scrollTo(10,100)
  if Session <> Nil then
    Session.ExecuteJavaScript( "var container = document.getElementById('" + c.ControlID + "');container.scrollTo(" + X.ToString + "," + Y.ToString + ");" )
  end if
End Sub
Public Sub scrollToBottom(extends c as WebContainer)
  '// myContainer.scrollToBottom
  if Session <> Nil then
    session.ExecuteJavaScript( "var container = document.getElementById('" + c.ControlID + "');container.scrollTop = container.scrollHeight - container.clientHeight;" )
  end if
End Sub
Public Sub scrollToTop(extends c as WebContainer)
  '// myContainer.scrollToTop
  if Session <> Nil then
    Session.ExecuteJavaScript( "var container = document.getElementById('" + c.ControlID + "');container.scrollTop = 0;" )
  end if
End Sub

I think this is multi-session safe. Not operating at 100% today. @Greg_O_Lone can say for sure.

4 Likes

Thanks Anthony. Works a treat

1 Like

Happy to help!

1 Like

Hi,
I’m using 2021 r1 and have added the module and methods as in the solution, however my Webviewer Container only scrolls half way up the page and stops (Method I’m using is ScrollToTop I have tried putting in a value less than zero, but still no difference.

Any ideas would be appreciated.

Without knowing more about your setup, there’s not really much help I can provide. Could it be that you have overlapping containers? Maybe have containers within containers and need to scroll more than one or you’re scrolling the wrong one?

No, that wouldn’t work as 0 is the minimum value.

1 Like

Hi Anthony,
Many thanks for your reply helped me tremendously and the problem is now solved - I was scrolling my PageViewer (Container) and not my page container array that was displayed within it.

Read your reply and the penny dropped for me, once again many thanks for your helpful nudge in the right direction to solve it.

All the best,

Colin

Happy to help!

1 Like

Thanks Anthony. Very useful

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.