Auto-Scroll if Opened on iPads

Hi everyone,

First of, I’m completely new to not only velo but also java, so please forgive me if my problem seems weird or stupid to you…

I’m experimenting with an extremely minimalistic page like this:

I’m trying to get it auto-scroll to the bottom after 0.5 second, ONLY IF the page is opened on iPads.

However, when I use the ‘if’ statement to detect if the page is opened on iPads, the “auto-scroll” code just does not work. Here’s the code I used to detect device and auto-scroll:

$w.onReady(function () {
    if ((navigator.userAgent.match(/iPad/i))) {
        setTimeout(() => {
            $w('#anchor1').scrollTo()
        }, 500);
    }
});

When I remove the ‘if’ statement, then the “auto-scroll” code works just fine. Here’s the code that’s working for me (which I got from Itai Pelles):

$w.onReady(function () {
     setTimeout(() => {
          $w('#anchor1').scrollTo()
     }, 500);
});

Yet I only want the page to auto-scroll on iPads ONLY. As soon as I remove the ‘if’ statement, the page auto-scrolls on all devices (which I don’t want to happen).

So I would really like to know if I’ve messed up with the code, or if not, are there any ways I can achieve my goal?

Thank you in advanced…

I also tried this code but it doesn’t seem to work either…

import wixWindow from 'wix-window';

$w.onReady(function () {
    if (wixWindow.formFactor === "Tablet") {
        setTimeout(() => {
            $w('#anchor1').scrollTo()
        }, 500);
    }
});

:frowning:

Can you try getBoudRect()? You can get the screen width with this.