0

I have a page with an element that moves when certain events fire. I'm using a CSS3 transition to make it move smoothly. It works great on Firefox, Chromium (Google Chrome), and Safari (Windows), Android Browser (2.3.7), and Firefox Mobile for Android (a.k.a. Fennec). On Internet Explorer, it ignores the transition property and just moves the element suddenly as expected.

It's not working on Mobile Safari, though. If I have -webkit-transition defined, the element doesn't move at all. I'm testing with a 1st gen iPod Touch, so this may only be an issue with older versions. My iOS version is 3.1.3 (7E18).

JavaScript animation effects (via jQuery) work okay, but don't run as smoothly on any of the devices mentioned. I'd rather use the CSS3 solution.

Is this a problem with newer iOS devices as well?

Is the problem documented and explained? If so, can someone provide a link?

Is there a work-around?

I've created a simple test page demonstrating my problem. As I've said, the element doesn't move in Mobile Safari unless I remove the -webkit-transition line.

<!doctype html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1">
    <style type="text/css">
        #box {
            border: 3px outset gray;
            font-size: xx-small;
            color: silver;
            background-color: black;
            position: absolute;
            width: 50px;
            height: 50px;
            top: 100px;
            left: 220px;
            -webkit-transition: all 1s ease;
            -moz-transition: all 1s ease;
        }

        a {
            display: table-cell;
            text-align: center;
            vertical-align: middle;
            color: black;
            text-decoration: none;
            width: 100px;
            height: 100px;
            background-color: silver;
            border: 2px outset gray;
        }
    </style>

    <script type="text/javascript">
        var box;
        window.onload = function(){
            box = document.getElementById("box");
        }

        var getTop = function(obj){
            var curtop = obj.offsetTop;
            obj = obj.offsetParent;
            while (obj){
                curtop += obj.offsetTop;
                obj = obj.offsetParent;
            }
            return curtop;
        };

        var moveUp = function(obj){
            var curtop = getTop(obj);
            obj.style.top = (curtop - 20) + "px";
            return false;
        };

        var moveDown = function(obj){
            var curtop = getTop(obj);
            obj.style.top = (curtop + 20) + "px";
            return false;
        };
    </script>
</head>
<body>
    <div id="box">
        <p>This is the box.</p>
    </div>

    <a href="#" onclick="return moveUp(box);">Move Up</a>
    <a href="#" onclick="return moveDown(box);">Move Down</a>
</body>
</html>

Thank you.

  • Does IOS 3 support css3 transitions? – H Bellamy Jan 05 '12 at 09:47
  • @HBellamy While trying to figure this out, I did a search for how to test if the browser supports CSS3 transitions. The answer is to test `if ("WebkitTransition" in document.body.style)`. ref: [check browser css property support](http://stackoverflow.com/q/1342994/166560). Mobile Safari says it has support. Besides, if it didn't have support, it should ignore the property entirely like IE does. –  Jan 05 '12 at 11:03

1 Answers1

0

Your best bet would be to update to iOS 5 - newer software fixes old bugs... Which is why we all hate ie6 :)

I just checked a couple of mobile frameworks, and their support matrix(es) start at iOS 3.2 + a couple listed 3.1.3 as the first version they DON'T support.

Also, you might want to try console.logging & checking your logs from the iOS safari debug console. And you might want to try binding to a touch event instead of the default click handler for links. Could be something finnicky like that. Even the hash tag in the link could be causing the problem.

1nfiniti
  • 2,032
  • 14
  • 19