# Scrollto

**URL:** <https://forum.xojo.com/t/scrollto/62052>\
**Category:** Web\
**Created:** [March 15, 2021, 8:18pm UTC](https://forum.xojo.com/t/scrollto/62052 "2021-03-15T20:18:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Oxley](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_oxley/32/1629_2.png) [@Paul\_Oxley](https://forum.xojo.com/u/Paul_Oxley)\
**Post date:** [March 15, 2021, 8:18pm UTC](https://forum.xojo.com/t/scrollto/62052/1 "2021-03-15T20:18:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Oxley](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_oxley/32/1629_2.png) [@Paul\_Oxley](https://forum.xojo.com/u/Paul_Oxley)\
**Post date:** [March 16, 2021, 8:56am UTC](https://forum.xojo.com/t/scrollto/62052/2 "2021-03-16T08:56:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [March 16, 2021, 9:32am UTC](https://forum.xojo.com/t/scrollto/62052/3 "2021-03-16T09:32:37Z")

</div>

By the silence (and the LR [https://documentation.xojo.com/api/user\_interface/web/webcontainer.html](https://documentation.xojo.com/api/user_interface/web/webcontainer.html)) I assume you are correct that ‘there no webcontainer.scrollto’.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [March 16, 2021, 9:34am UTC](https://forum.xojo.com/t/scrollto/62052/4 "2021-03-16T09:34:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Oxley](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_oxley/32/1629_2.png) [@Paul\_Oxley](https://forum.xojo.com/u/Paul_Oxley)\
**Post date:** [March 16, 2021, 9:47am UTC](https://forum.xojo.com/t/scrollto/62052/5 "2021-03-16T09:47:17Z")

</div>

Cheers Anthony.

Much Appreciated

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [March 16, 2021, 10:38am UTC](https://forum.xojo.com/t/scrollto/62052/6 "2021-03-16T10:38:26Z")

</div>

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

```xojo
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

```

```xojo
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

```

```xojo
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.

---

<div class="post-metadata">

**Author:** ![Paul\_Oxley](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_oxley/32/1629_2.png) [@Paul\_Oxley](https://forum.xojo.com/u/Paul_Oxley)\
**Post date:** [March 16, 2021, 12:08pm UTC](https://forum.xojo.com/t/scrollto/62052/7 "2021-03-16T12:08:37Z")

</div>

> [@Anthony\_G\_Cyphers](#):
>
> ```auto
> 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
> 
> ```

Thanks Anthony. Works a treat

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [March 16, 2021, 1:53pm UTC](https://forum.xojo.com/t/scrollto/62052/8 "2021-03-16T13:53:04Z")

</div>

Happy to help!

---

<div class="post-metadata">

**Author:** ![Colin\_Scarrott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@Colin\_Scarrott](https://forum.xojo.com/u/Colin_Scarrott)\
**Post date:** [May 5, 2021, 7:29pm UTC](https://forum.xojo.com/t/scrollto/62052/9 "2021-05-05T19:29:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [May 8, 2021, 6:09am UTC](https://forum.xojo.com/t/scrollto/62052/10 "2021-05-08T06:09:31Z")

</div>

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?

> [@Colin\_Scarrott](#):
>
> I have tried putting in a value less than zero, but still no difference.

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

---

<div class="post-metadata">

**Author:** ![Colin\_Scarrott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@Colin\_Scarrott](https://forum.xojo.com/u/Colin_Scarrott)\
**Post date:** [May 8, 2021, 3:24pm UTC](https://forum.xojo.com/t/scrollto/62052/11 "2021-05-08T15:24:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [May 8, 2021, 3:25pm UTC](https://forum.xojo.com/t/scrollto/62052/12 "2021-05-08T15:25:39Z")

</div>

Happy to help!

---

<div class="post-metadata">

**Author:** ![Calvi\_Tecnologie\_srl\_Calvi](https://forum.xojo.com/user_avatar/forum.xojo.com/calvi_tecnologie_srl_calvi/32/519_2.png) [@Calvi\_Tecnologie\_srl\_Calvi](https://forum.xojo.com/u/Calvi_Tecnologie_srl_Calvi)\
**Post date:** [June 8, 2021, 8:09pm UTC](https://forum.xojo.com/t/scrollto/62052/13 "2021-06-08T20:09:51Z")

</div>

Thanks Anthony. Very useful

---

<div class="post-metadata">

**Author:** ![John\_Scanlan](https://forum.xojo.com/user_avatar/forum.xojo.com/john_scanlan/32/472_2.png) [@John\_Scanlan](https://forum.xojo.com/u/John_Scanlan)\
**Post date:** [June 29, 2021, 4:08am UTC](https://forum.xojo.com/t/scrollto/62052/14 "2021-06-29T04:08:31Z")

</div>

Thanks for creating this. In my case I’m adding rows ■■■ webContainers to another webContainers (it looks like a proper listbox).

When I add a row and run the code, scrollToBottom scrolls to the bottom less one row.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [June 29, 2021, 5:53am UTC](https://forum.xojo.com/t/scrollto/62052/15 "2021-06-29T05:53:57Z")

</div>

I just tested it and it seems to work for me. Try this project:  
[https://www.dropbox.com/s/uh41vzisabkv8nm/container-scrollto.xojo\_binary\_project?dl=1](https://www.dropbox.com/s/uh41vzisabkv8nm/container-scrollto.xojo_binary_project?dl=1)

---

<div class="post-metadata">

**Author:** ![John\_Scanlan](https://forum.xojo.com/user_avatar/forum.xojo.com/john_scanlan/32/472_2.png) [@John\_Scanlan](https://forum.xojo.com/u/John_Scanlan)\
**Post date:** [June 29, 2021, 8:13pm UTC](https://forum.xojo.com/t/scrollto/62052/16 "2021-06-29T20:13:49Z")

</div>

That worked using the button to scroll. Look at this edit. The idea is to add the container and have it automatically scroll to the bottom so the bottom row always shows without the need to press a button. See button 4

[https://www.dropbox.com/home?preview=container-scrollto+(scanlan).xojo\_binary\_project?dl=1](https://www.dropbox.com/home?preview=container-scrollto+(scanlan).xojo_binary_project)

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [June 29, 2021, 8:17pm UTC](https://forum.xojo.com/t/scrollto/62052/17 "2021-06-29T20:17:35Z")

</div>

Couldn’t download your file (File Doesn’t Exist), but I added the following Shown event to ccVertical and it worked as expected:

```xojo
Sub Shown() Handles Shown
  me.scrollToBottom
End Sub

```

You could potentially use Timer.CallLater depending on what you need.

---

<div class="post-metadata">

**Author:** ![John\_Scanlan](https://forum.xojo.com/user_avatar/forum.xojo.com/john_scanlan/32/472_2.png) [@John\_Scanlan](https://forum.xojo.com/u/John_Scanlan)\
**Post date:** [June 29, 2021, 8:19pm UTC](https://forum.xojo.com/t/scrollto/62052/18 "2021-06-29T20:19:07Z")

</div>

Could you upload that because there’s no ccVertical in the original?

How do you have do a download link to a dropbox file?

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [June 29, 2021, 8:22pm UTC](https://forum.xojo.com/t/scrollto/62052/19 "2021-06-29T20:22:26Z")

</div>

There is. I just redownloaded the example and modified it because I don’t normally keep stuff like this around.

 ![Screen Shot 2021-06-29 at 4.21.39 PM](https://forum.xojo.com/uploads/default/original/2X/6/6cb602ca27148c3c45d87623a61d7be47a8af887.png)

---

<div class="post-metadata">

**Author:** ![John\_Scanlan](https://forum.xojo.com/user_avatar/forum.xojo.com/john_scanlan/32/472_2.png) [@John\_Scanlan](https://forum.xojo.com/u/John_Scanlan)\
**Post date:** [June 29, 2021, 8:46pm UTC](https://forum.xojo.com/t/scrollto/62052/20 "2021-06-29T20:46:21Z")

</div>

The one I downloaded (thank you again) has ccParent rather than ccVertical and ccHorizontal.  
 ![container-scrollto](https://forum.xojo.com/uploads/default/original/2X/d/d0c59082514600827cf3d5a38b9ce1a3be8a9582.png)

Maybe the programming is not the same ?

[Next page](https://forum.xojo.com/t/scrollto/62052.md?page=2)
