iOS Devices and page transitions

Often happens that customers require to implement transitions between pages, nice animations, etc. also in a mobile web sites.
This kind of effects usually belong to Flash web sites but unfortunately on iOS devices there is still no support for Flash. Thanks to “Stevie” in fact the web on the mobile is growing up without the Flash Player but the request the customers have are always the same: nice transitions, cool effects, etc.
The result is that we have to use technologies that are pretty new and without a strong background like Flash to satisfy customer’s request.
Anyway, let’s see hot to create a transition effect on an iOS device with CSS and the webkit transitions.

It’s pretty easy to create a page transition effect using the webkit transitions in a CSS file or declaration.
As of June 2011, Firefox 5 includes CSS Animation support. CSS animation is also available as a module in the nightly builds of WebKit as well as Google Chrome, Safari 4 and 5 and Safari for iPhone, Android 2.x and 3.x, the RIM OS6 web browser, with the -webkit- prefix.

The syntax to define a transition is pretty sample, it’s enough to use the @-webkit-keyframes directive followed by the name of the transition

[cce_css]
@-webkit-keyframes NAME-YOUR-ANIMATION {}
[/cce_css]

In the curly braces that follow the name of the transition it’s possible to define which properties have to be changed at a specific time

[cce_css]
0%{
font-size: 10px;
}
50%{
font-size: 20px;
}
100%{
font-size: 30px;
}
[/cce_css]
If an animation has the same starting and ending properties, you can comma separate the percentage values and define the properties

[cce_css]
0%, 100%{
font-size: 30px;
}
[/cce_css]
If you want to create infinite animation you can do it easily combining transitions and transformation.
In this case usually the from and to keyword are used but actually have the same meaning of 0% and 100%.

In order to create a fade in page effect you can just declare in a CSS file two animations

[cce_css]
@-webkit-keyframes reset {
0% {
opacity: 0;
}
100% {
opacity: 0;
}
}

@-webkit-keyframes fadein {
0% {
opacity: 0;
}
60% {
opacity: 0;
font-size: 25px;
}
100% {
opacity: 1;
font-size: 45px;
}
}
[/cce_css]
The first one is the one needed to make the page blank when loaded.
After you define the animations it’s enough to create a new CSS class specifying which animations to use, the duration, the timing function and the iteration count

[cce_css]
.fadein {
-webkit-animation-name: reset, fadein;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease-in;
-webkit-animation-iteration-count: 1;
}
[/cce_css]
If you want that the elements in your page fade in with a specific amount of delay you can add the following lines to your CSS

[cce_css]
.fadein.first {-webkit-animation-delay: 0, 0;}
.fadein.second {-webkit-animation-delay: 0, 1s;}
.fadein.third {-webkit-animation-delay: 0, 1.5s;}
[/cce_css]
In the HTML page you have to import your CSS and use the sub classes already defined in order to see your animations working properly

[cce_xml]
<div>
The content you want to show <b>first</b>…
</div>

<div>
The content you want to show <b>second</b>…
</div>

<div>
The content you want to show <b>third</b>…
</div>
[/cce_xml]
The sample animation defined above changes also the font size, actually I did it just in order to show that you can combine more than one properties and create pretty nice effect to show the elements of your pages.

Comments

comments

Leave a Reply

Your email address will not be published.


*