My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Animations  
How to use built-in animations and make your own
Featured
Updated Oct 5, 2009 by davidcol...@gmail.com

Animations

By default, jQTouch comes with 8 page animations: slide, slideup, dissolve, fade, flip, pop, swap, and cube. The links which cause these animations to occur can be customized via their corresponding initialization options (default values shown below):

  • slideSelector: 'body > * > ul li a'
  • slideupSelector: '.slideup'
  • dissolveSelector: '.dissolve'
  • fadeSelector: '.fade'
  • flipSelector: '.flip'
  • popSelector: '.pop'
  • swapSelector: '.swap'
  • cubeSelector: '.cube'
  • backSelector: '.back, .cancel, .goback'

How Animations Work

It is important to note that all animations are handled with CSS3 and classes. Each time the user navigates to a new page, two animations occur: The new page animating in and the old page animating out. The classes which are applied during an animation are:

  • <div id="#oldpage" class="_transitionname_ out">
  • <div id="#newpage" class="_transitionname_ in">

When the user hits a back button, an additional class of "reverse" is added to both elements.

Adding Custom Animations

Adding your own animations is straight-forward. Just add the corresponding class definitions (using CSS3 keyframe animations), and add the animation with the corresponding public function. Here's an example of adding a custom "reveal" animation, where the new page slides in overtop of the old page.

<script>
    var jQT = new $.jQTouch();

    $(function(){
        jQT.addAnimation({
            name: 'reveal',
            selector: '.revealme'
        });
    });
</script>

<style>
    .reveal.in {
    	-webkit-animation-name: dontmove;
    	z-index: 0;
    }

    .reveal.out {
    	-webkit-animation-name: revealout;
    	z-index: 10;
    }

    .reveal.out.reverse {
    	z-index: 0;
    	-webkit-animation-name: dontmove;
    }

    .reveal.in.reverse {
    	z-index: 10;
    	-webkit-animation-name: revealin;
    }


    @-webkit-keyframes revealin {
        from { -webkit-transform: translateX(100%); }
        to { -webkit-transform: translateX(0); }
    }

    @-webkit-keyframes revealout {
        from { -webkit-transform: translateX(0); }
        to { -webkit-transform: translateX(100%); }
    }
</style>

You will note we're using a built-in animation "dontmove" on pages which are stationary during the transition. This is important, as it means an animation is still technically running on the object (so callback functions still work).

Disabling Animations

Passing 'useAnimations: false' will disable all animations, swapping views instantly -- though still using the same selectors listed above.

Comment by joshua.s...@gmail.com, Oct 8, 2009

If you want to slide in from the left instead of the right (what I called "slideback"), here is the code to add:

<script>
$(function(){
    jQT.addAnimation({
        name: 'slideback',
        selector: '.slideback'
    });
});
</script>

<style type="text/css" media="screen">
/* Custom Animations */
.slideback.in 			{ -webkit-animation-name: slideinfromleft; }
.slideback.out 			{ -webkit-animation-name: slideouttoright; }
.slideback.in.reverse 	{ -webkit-animation-name: slideouttoright; }
.slideback.out.reverse 	{ -webkit-animation-name: slideinfromleft; }

</style>
Comment by project member davidcol...@gmail.com, Oct 10, 2009

Thanks Josh, great example. I'm also currently working on the ability to just do something like: <a href="#newpage" class="flip reverse"> to automatically use reverse transitions.

Comment by julioved...@gmail.com, Nov 11, 2009

I want to load via ajax an html content and then make slideup effect. I'm making in this way, but don't work in iphone, only in firefox Desktop:

<script type="text/javascript">
    		$(function(){
        		$('a[href="#clickme"]')
        			.click(function(){
            			$.get(
                   			'another_page.html', 
                   			'', 
                   			function(data){
                       			data = $(data.replace(/[\r\n]/g,'').match(/<body[^>]*>(.*)<\/body>/)[1]);
                       			$('div#result-div').html($(data.get(0)).html());
                       			//simulate fake click to active effect
                       			$('<a href="#result-div" class="slideup" />').click();                       			
                       		}, 
                       		'text'
                        );
                        this.blur();
                     	return false;
            		});
        	});
    	</script>

How I need to make to this works in iPhone correctly?

Comment by lord....@gmail.com, Nov 18, 2009

slideSelector: 'body > * > ul li a'

This means that a link will work in an <li> which is in an <ul> which is in some <element> in the body.

This will not work due to two divs:<body><div><div><ul><li><a></a></li></ul></div></div></body>

Solution: Initilize as

            var jQT = $.jQTouch({
				icon: 'img/icon1.png',
				statusBar: 'black-translucent',
				slideSelector: 'body > * > ul li a, .forceSlide'
			});
Comment by sam.burc...@gmail.com, Dec 2, 2009

Hey,

Is there a way to animate away from one HTML page and seemlessly into another?

Comment by vkan...@gmail.com, Dec 3, 2009

Hi,

When I click a link at the bottom of a long list of a page to slide to another page, the old page always scrolls up to the page top before sliding to the new page.

Is it possible to stay in the current position of the old page (no more scroll up) before sliding to the new page ??

Thanks

Comment by sherif.t...@gmail.com, Dec 9, 2009

Hey juliovedovatto, To get your code to work, use pageAnimationEnd() instead of click(). E.g.

$('a[href="#clickme"]').bind('pageAnimationEnd',function(e,info)

In other words, fire off your AJAX after the page animations are completed, instead of attaching it to the click event.

Comment by rohailal...@gmail.com, Dec 20, 2009

what is the class of the animation that occurs when the back button is pressed? I want to use it in a pagination script and .back .cancel and .goback doesnt work :S

Can anyone help?

Comment by chuckbur...@gmail.com, Jan 10, 2010

hey rohailaltaf, did you receive an answer to your question? I'm curious as well.

Comment by norway.r...@gmail.com, Jan 13, 2010

I desperately need a way to animate backwards sliding to a link, not just for pages back in history!

I have tried the custom animation "slideback" code posted above by Joshua S but that does not work for me no matter what I try!

I would love to use something like <a href="#newpage" class="flip reverse"> (as posted by David above) but I need it to point to a page that isn't currently loaded, like href="menu.php" or the java similar href="menu.do"

Please explain how this can be done! Cheers for an excellent platform to build on if these bugs (or lacking features) could be worked out.

Comment by kahler.a...@gmail.com, Jan 27, 2010

The slideback animation CSS has to look like this (going back did not work correctly):

            /* Custom Animations */
            .slideback.in           { -webkit-animation-name: slideinfromleft; }
            .slideback.out          { -webkit-animation-name: slideouttoright; }
            .slideback.in.reverse   { -webkit-animation-name: slideinfromright; }
            .slideback.out.reverse  { -webkit-animation-name: slideouttoleft; }
                 

Then use it like this (assuming you added it with addAnimation as shown above):

            <ul class="individual">
                <li><a class="slideback" href="#animdemo">&lt;&lt;</a></li>
                <li><a class="slide" href="#animdemo">&gt;&gt;</a></li>
            </ul>
Comment by df.creat...@gmail.com, Feb 26, 2010

Hello. Does anybody know how to remove unpleasant blinks when the animation ".slideback" ends?

Comment by amar.chi...@gmail.com, Mar 14, 2010

I am having a series of <div> with a position:absoloute in their class property, so that they all overlap on each other. I am trying make a book like fee to the user, so that when they swipe from right to left the next page is shown and when they swipe from left to right the page goes back...

For this I am trying to use the swipe.. with out any buttons.. How can I get this swipe to work in these <div>'s on my page... ??? Please

Comment by navin.k....@gmail.com, Mar 26, 2010

I'm working on a similar problem as Amar and getting a little stuck. I'm able to 'capture' the swipe event on the page but I'm not exactly sure how to tell jQTouch to transition to the next page, and what URL to use. Any clarification/examples on this would be welcome...

Comment by Naoyuki....@gmail.com, Apr 9, 2010

At iPhoneOS4.0β , all animations are not smooth....

Comment by hackf...@gmail.com, Apr 15, 2010

I have the same problems in 4.0

Comment by pstanw...@gmail.com, Apr 25, 2010

I have a HTC desire and the animations do not work.

Has anyone got the Animations to work on the Anroid 2.1 browser?

Comment by martin.m...@adventisdigital.com, May 19, 2010

@pstanway - slide animation works fine on my desire. Might be worth double checking you have your selectors set correctly

Comment by cvied...@gmail.com, May 19, 2010

On an iPad the animations blink when they are finishing. Something wrong :(

Comment by grantsan...@gmail.com, May 31, 2010

@cviedmai- are you using sdk emulator or actual device?

Comment by grantsan...@gmail.com, May 31, 2010

@navin.k.prasad and @amir

You should use multiple DIVs on same html page for this. Faster load, less page requests. Hide all divs and show the next each time a swipe occurs. Great example in the demos- Check out jqtouch<latest>/demos/customanimation2/

Comment by drd...@gmail.com, Jun 1, 2010

@grantsanders I also see blinking when the animations stop when using an actual iPad device.

Comment by brett.sp...@gmail.com, Jun 3, 2010

On iPhone OS 4 Beta 4+, the animations work very smoothly (whereas they did not on earlier Beta releases). I would have no concerns that the final OS 4 will handle the animations fine.

Comment by pmansfi...@graphixtyle.com.au, Jun 30, 2010

@drdawn I'm also experiencing flashing (blinking) on 2 iPads. Any update's?

Comment by ack...@gmail.com, Jun 30, 2010

working on the Androids 1.5 - 2.1 using the slideback transition.

Both hard devices and emulators blink after a page load. what I mean by blink is after the new page loads, the previous page shows up on the screen for a split second before disappearing.

Also have problems with navigation, if I click the same link twice, it complete messes up the page load.

--in Start page -- <a class="menubutton" href="#">Start Page</a> <a class="menubutton in" href="#nextPage">Next Page</a>

--in Start page -- <a class="menubutton in" href="#nextPage">Start Page</a> <a class="menubutton" href="#">Next Page</a>

If I navigate to the "Next Page", and click the "Next Page" button again, it blinks a few of my pages and puts me back to "Start Page".

Am I doing something wrong with my links or can someone point me in the right direction? Or is it because like most other Web UI, this is directed mainly at the Apple devices?

Comment by dhananay...@gmail.com, Jul 1, 2010

how to use function animatePages(fromPage, toPage, animation, backwards)

Comment by buchtb...@gmail.com, Jul 17, 2010

i have solved the blinking problem with a little help from z-index

what comes in gets a 10, what goes out gets a 0

like this:

.slide-back.in {

-webkit-animation-name: slideinfromleft; z-index: 10;
}

.slide-back.out {

-webkit-animation-name: slideouttoright; z-index: 0;
}

.slide-back.in.reverse {

-webkit-animation-name: slideinfromright; z-index: 10;
}

.slide-back.out.reverse {

-webkit-animation-name: slideouttoleft; z-index: 0;
}

@-webkit-keyframes slideinfromright {

from { -webkit-transform: translateX(100%); } to { -webkit-transform: translateX(0); }
}

@-webkit-keyframes slideinfromleft {

from { -webkit-transform: translateX(-100%); } to { -webkit-transform: translateX(0); }
}

@-webkit-keyframes slideouttoleft {

from { -webkit-transform: translateX(0); } to { -webkit-transform: translateX(-100%); }
}

@-webkit-keyframes slideouttoright {

from { -webkit-transform: translateX(0); } to { -webkit-transform: translateX(100%); }
}

Comment by carbon.c...@gmail.com, Jul 20, 2010

@buchtblog are you changing this in the jqtouch.css? coz it seems the exisiting -webkit-keyframes already have those values.

Comment by edzio...@gmail.com, Jul 20, 2010

@buchtblog: your solution seems to work great. But I'm still having the blink problem with slideup on my Htc desire. I tried to play a little with the z-index but no go.. I'm wondering is this a bug in jqtouch or maybe webkit is not rendering it correctly?

Comment by i...@dglab.it, Jul 21, 2010

Compliments for jtouch!

In slide animations i want to create a photogallery with slide from next button. Now...how i can change back button in next button? ( i'have tried with modify to css but always return on animations page)

thanks

Comment by buchtb...@gmail.com, Jul 23, 2010

@ carbon caleb no, i've put the z-indexes in the css i made for the page, since the slide-back animation is not between the original stuff. i've seen some z-indexes in jqtouch.css but they seem to be used differently.

@edziohtc i'm sorry, cannot help you with that. only logic says: what comes in must lie above what goes out.

Comment by mari...@poczta.fm, Jul 24, 2010

@buchtblog: it works in case of slideup, but not with reverse :) I tried to put z-index in every known combination and still the blink is visible.. but only in reverse (?!)

Comment by don.bart...@gmail.com, Aug 10, 2010

@i...@dglab.it - "how to make a next button": see the comment above from "lord.loh, Nov 18, 2009" and the use of a .forceSlide class - worked for me.

Comment by mrspea...@gmail.com, Aug 16, 2010

I think the flash at the end of animation that some people are seeing is because the page they are transitioning have a transparent background (all of the jQTouch example pages have solid backgrounds).

Elements that are animated with webkit-animation will snap back to their starting position after the animation concludes -so the element is transitioned off the screen, then snaps back to it's original position (on screen) then the "current" class is removed by jQtouch - which hides it, causing a "flash".

I can't see a way to force webkit-animation to not return to the start... anyone know how?!

Comment by sumit.gr...@gmail.com, Aug 26, 2010

Do any body know how to make pagination work in jqtouch ?? if anybody have code please help

Comment by sebastia...@gmail.com, Aug 27, 2010

I have also the problem of flashing at animations @cviedmai and the solution of @buchtblog won't work :(

But I noticed, if the target div bigger than the ipad, there is no flashing. So somebody knows how to set all divs to the full size, even if their content are not enough?

Thanks for helping.

Comment by parisfel...@gmail.com, Sep 2, 2010

Well, after months or working with JQtouch and endless nights, I was able to make it look, feel and behave flawlessly...including perfect-smooth scrolling and fast response times. Got rid of even the slightest glitches. My apps are super-heavy with truly huge data arrays, a lot of hi-res images and a LOT of Ajax. Imagine main html file over 1MB before loading data? It was super hard to make this work at all, not to say to work like a dream. My main advice for those who are looking for better, faster response times and smooth performance: have everything inline, no external css or JS all frameworks must be in the parent. Even Jquery has to be internally run. All buttons, images, etc, must be in the same directory. There are a few tricks how to make scrolling jitter-free and smooth like a dream as well!:) P.S I also had to slightly rewrite some core JQtouch functions.

Comment by manmadei...@gmail.com, Sep 9, 2010

Hi parisfelinni Do you have a example? Im interesting in "tricks how to make scrolling jitter-free and smooth like a dream", since scrolling long lists is not smoot at all for me.

Comment by daaa57150@gmail.com, Dec 18, 2010

For people who have a blinking problem, maybe this can help you. I have a button on my homepage that animates another page in using a slideup. When I tap that button, the homepage blinks to black before the other page comes in. I use the jqt theme, on an ipod touch with iOS 3.1. After some tests, I figured this is because the size of the div that comes in is longer than the screen. So I resolved it with this function, call it in your onready/$ function:

var fixPageBlinks=function()
{
    $("div[id=\"jqt\"] > div").each(function()
    {
        var el=$(this);
        //console.log("fix blink for page "+el.attr("id"));
        el.bind('pageAnimationStart', function(e, info){ 
            el.css("height","480px");
        }).
        bind('pageAnimationEnd', function(e, info){
            el.css("height","auto");
        });
    });
}

Now I can see a small color change in the backgrounds during animation but it's not that bad.

Comment by juanbr...@gmail.com, Dec 21, 2010

Blink problem solved! Here's the recipe:

- open jqtouch.js (if you're using jqtouch.min.js, must change it to this modified jqtouch.js)

- goto line 345 (scrollTo(0, 0);) and after that add: // mod1 var toStart = 'translateX(' + (backwards ? '-' : '') + window.innerWidth + 'px)'; fromPage.css( 'webkitTransform', toStart ); // end mod1

- then goto line 350 (was 348 before mod1, just after var callback = function(event){ ) and add: // mod2 fromPage.css( 'webkitTransform', ''); // end mod2

Done, that's all!

Comment by sentenza...@gmail.com, Feb 6, 2011

It could be interesting to use these animations between two HTML pages... Someone knows if it already exists ? Or need to be developed ?

Beny

Comment by addydmasi, Feb 6, 2011

To those who want to animate between two separate web pages, try this in your <body>:

<div id="main"><ul><li><a href="#page1" class="slide">Go to another page</a></li></ul></div>
<div id="page1"><iframe src="http://google.com">Error</iframe></div>

Replace the src with the file name of the second page and also "page1" with any other name. Then add this to your <head>:

<style type="text/css">div>iframe{width:100%;height:100%;margin:0;padding:0;border-width:0;}</style>

Load the page, tap the link and the external page will slide in. Enjoy!

Comment by sunke.pr...@gmail.com, Feb 11, 2011

it is possible to have iPhone like flipping between 2 different activities in android. Can you please post the required code

Comment by addydmasi, Feb 11, 2011

sunke.pr...@gmail.com The "swap" animation is similar to the iPhone's animation between two apps. Here is some code you can use to test it:

<div id="main"><ul><li><a href="#page1" class="swap">Swap</a></li></ul></div>
<div id="page1"><ul><li><a href="#main" class="swap">Back</a></li></ul></div>
Comment by Emil.Abr...@gmail.com, Mar 1, 2011

Is it possible to animate a part of the page and keep the same toolbar? For example to load a new content to a <div class="info" id="datafield"> using AJAX when a button is pressed in the toolbar?

Comment by ahirebhu...@gmail.com, Mar 3, 2011

How I can implement something like twitter app does. When we swipe on tweet it slides with the options icons.

Comment by zhou...@chinawalker.com, Mar 7, 2011

I'm using iFrame like addymasi suggested (I'm using swiping to change pages). The transition to another is quite smooth. But the iFrame is not arranged very well, I guess this could be fixed by adjust css. The main problem is the swipe (or touch) is not captured inside this iFrame. I can't use swipe to move back to my previous page any more. Any suggestion?

Comment by manpreet...@gmail.com, Apr 12, 2011

I have to create a functionality in which i have to slide up only a portion of the page. e.g if user has opened any page and he has got any new message then whatever page he has opened, a new bubble with the message text will appear with slide in animation.

I am able to append the HTML in the current opened page but not able to do it with animation as animate will slide out the full page.

Any ideas on how i can do this? Thanks in advance.

Comment by danielda...@gmail.com, Jun 22, 2011

Is there a way to navigation from page to page with animations without using an iframe? This seems like a glaring oversight in how jqtouch works. Wouldn't it be fairly normal that someone would want to load up dynamic pages of a site without calling on-page divs?

Comment by addydmasi, Jun 22, 2011

@danielda...@gmail.com You can load a page via Ajax instead, however, the page we load must have a back button otherwise the user can't go back to the previous page. In the first page:

<script>
$(function(){
    $("#page2").load("/path/to/another/page.html #page2");
});
</script>

Change "page2" above with the id you want for the page, and /path/to/another/page.html with an absolute or relative limk to the page you want to load. Then create another page with jQuery and jQTouch and add a div in the body that has the id you chose above. Ad@m

Comment by blueligh...@gmail.com, Jul 6, 2011

How might I implement this if I just want to load options for one item on a list? A common iphone UI element is tapping or sliding to reveal other options beneath a list item (twitter's app does this, for example.)

Comment by nexus6.n...@gmail.com, Nov 8, 2011

i think blinking has smthing to do with 1024x1024 UIview limitation .. see http://stackoverflow.com/questions/273067/iphone-sdk-uiwebview-has-a-grey-box-over-it

Comment by junior.a...@gmail.com, Nov 29, 2011

Can anyone please help me? I am using the following code to open another page but when you click it shows a blank page instead of the page I am trying to open.

<html> <head> <title>This is a test app</title> <link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css"> <link type="text/css" rel="stylesheet" media="screen" href="themes/jqt/theme.css"> <script type="text/javascript" src="jqtouch/jquery.js"></script> <script type="text/javascript" src="jqtouch/jqtouch.js"></script> <script type="text/javascript">

var jQT = $.jQTouch({
icon: 'kilo.png', statusBar: 'blue'
});
</script>
</head> <body>
<div id="home">
<div class="toolbar">
<h1>Setup</h1>
</div> <ul class="edgetoedge">
<li class="arrow"><a href="iphoneEditShoppingItems.aspx">Edit Shopping Items</a></li>
</ul>
</div>
</body>
</html>

Comment by shahzad4...@gmail.com, Jan 11, 2012

arttreee www.arttreee.com its good for web designing.....


Sign in to add a comment
Powered by Google Project Hosting