Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad Safari improper scrolling in RTL with wide content

The condition is as follows:

  1. Using iPad Safari
  2. Page is in RTL (right to left) mode (Arabic locale)
  3. Page dynamically loads some content which is wider than the screen
  4. Strange scrolling behavior occurs

The page starts out seemingly scrolled too far to the left (see the screenshot), so the right-hand side (what is normally the left in LTR mode) is towards the middle and what seems like negative space is displayed instead.

You can touch-drag to right to scroll left to see some contents that start off-screen, but I can only scroll part way, which leaves some content far off to the left that is impossible to get to.

Here is a screenshot from defect I'm working on:

Screenshot of the initial state

Here is a simple HTML that could reproduce the problem:

<!DOCTYPE html>
<html dir="rtl">
<head>
<meta name="viewport" content="minimum-scale=0.25, maximum-scale=4.0, user-scalable=yes" />
</head>
<body style="background-color:grey">
<script src="http://code.jquery.com/jquery.js"></script>
<script>
    setTimeout(function(){
        $('<div style="width:2000px;background-color:red">test</div>').appendTo('body');
    },1000);
</script>
</body>
</html>

Steps you can follow to reproduce the problem:

  1. Copy this HTML to a local file
  2. Open the document in Chrome, using F12 you can turn on iPad emulation

Chrome emulation

Press the button to emulate - then you will notice that the right edge of the red box is near the middle of the page. However, that should not be the case. That red box should be the only content, and nothing is to the right of it, so it should aligned with the right edge.

This issue also only happens when you dynamically insert the wide content after the page has loaded, so if the page starts out with wide content, the scroll behavior seems normal. Hence the setTimeout() in the code.

Any advice/workaround to fix this problem?

EDIT: You can also directly try this link to reproduce the problem: http://www.codefactor.net/ipadissue.html

like image 434
codefactor Avatar asked Jul 15 '15 20:07

codefactor


3 Answers

The only solution i found so far is by placing all your rtl content inside a container div. That made the sample code working as expected and should do it for all child content too.

(i tested iPad, chrome, safari desktop, and few other simulated devices within chrome dev-tools)

So just put everything inside it :

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="minimum-scale=0.25, maximum-scale=4.0, user-scalable=yes" />

</head>

<body style="background-color:grey">


    <div dir="rtl" id="container"></div>


<script src="http://code.jquery.com/jquery.js"></script>
<script>
    setTimeout(function(){
        $('<div style="width:2000px;background-color:red">test</div>').appendTo('#container');
    },1000);
</script>
</body>
</html>

iPad Safari rtl align issue


NOTE: You may also need to remove margins and/or paddings of the #container div by forcing them to 0s values in order to not break your design specially if is built on top of a CSS framework.

NOTE 2: I think this is an iPad's safari bug that we may need to report. When rtl the html or body tag, text get aligned correctly but divs get aligned to the wrong side (like if it was inside a classic ltr web page) and it happens only with iPad's Safari, not the desktop version.

like image 163
Salem Ouerdani Avatar answered Nov 19 '22 21:11

Salem Ouerdani


'Looks to me like the problem is your viewport meta tag.

Try this:

<meta name="viewport" content="width=device-width, initial-scale=1">

or just extend your existing meta tag like this:

<meta name="viewport" content="minimum-scale=0.25, maximum-scale=4.0, user-scalable=yes, width=device-width, initial-scale=1">
like image 2
Bangkokian Avatar answered Nov 19 '22 20:11

Bangkokian


This is a bug within WebKit and has been resolved by https://bugs.webkit.org/show_bug.cgi?id=146872.

See the change log here: https://bugs.webkit.org/attachment.cgi?id=256657&action=review

I don't know the release version though. Consider most iOS has browser updates with the OS update, this would patched soon (fixed as 2015-7-11).

like image 1
Tony Z Avatar answered Nov 19 '22 19:11

Tony Z