1

Hello folks at Stack Overflow from all over the world! hope you´re all doing great! I just have one inquiry today. I just found out about an awesome css3 library called animate.css http://daneden.github.io/animate.css/ which I am trying to implement with jquery mobile to custome my apps page transitions. I'm trying to go from one page to another with an animate.css class applied to the page div but after the fancy transition occured the page remains on same page and does not reach the targeted page. If anyone out there has any clue on how to achieve this, please let me know. Thanks Here the code:

CSS:

<link href="./css/animate.css" rel="stylesheet" />

Javascript:

<script language="javascript">
    $(function() {
        $("a#home").click(function() {
            animate(".box-a", 'rotateOutDownRight');
            return false;
        });

    });

    function animate(element_ID, animation) {
        $(element_ID).addClass(animation);
        var wait = window.setTimeout( function(){
            $(element_ID).removeClass(animation)}, 1300
        );
    }
</script>

HTML:

<!------- HOME PAGE ----------------------------------------> 

<div data-role="page" id="home" data-theme="c" class="box-a animated"> <!--Inicia pagina home -->
  <div data-role="header"><h1>Animate</h1></div>  

  <div data-role="content">

    <p><a id="home" href="#pagina2">Box A will flash, click here!</a></p>

    <a id="home" href="#pagina2" data-role="button">PAGE 2 W/ANIMATION.CSS</a>
    <a href="#pagina2" data-role="button">PAGE 2 W/O ANIMATION.CSS</a>            
  </div>      <!-- End of div content -->

  <div data-role="footer" data-position="fixed"><h3>Animate</h3></div>         
</div>

<!----- PAGE  2  -----------------------> 

<div data-role="page" id="pagina2" data-theme="c"> <!--Inicia pagina home -->
  <div data-role="header"><h1>Animate</h1></div>  

  <div data-role="content">

    <p>PAGE 2</p>    

  </div>  <!-- End of div content -->

  <div data-role="footer" data-position="fixed"><h3>Animate</h3></div>         
</div>

URL: see an example here: http://apps.alfonsopolanco.com

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
xzibit
  • 3,197
  • 2
  • 17
  • 19

1 Answers1

2

jQM allows you to define custom transition ( http://demos.jquerymobile.com/1.2.0/docs/pages/page-customtransitions.html ). Using animate.css for this is no problem.

Add 2 css rules that reference the desired transition from animate.css:

.customRotate.in {
    -webkit-transform: translateX(0);
    -moz-transform: translateX(0);
    -webkit-animation-name: rotateInUpRight;
    -moz-animation-name: rotateInUpRight;
}
.customRotate.out {
    -webkit-transform: translateX(0);
    -moz-transform: translateX(0);
    -webkit-animation-name: rotateOutDownRight;
    -moz-animation-name: rotateOutDownRight;
}

Then simply set the data-transition attribute on the anchor tag to the name of your new transition:

<a id="home" href="#pagina2" data-role="button" data-transition="customRotate">PAGE 2 W/ANIMATION.CSS</a>

Here is a DEMO

UPDATE: To control the speed of the transition:

.in {
    -webkit-animation-timing-function: ease-out;
    -webkit-animation-duration: 750ms;
    -moz-animation-timing-function: ease-out;
    -moz-animation-duration: 750ms;
}

.out {
    -webkit-animation-timing-function: ease-in;
    -webkit-animation-duration: 555ms;
    -moz-animation-timing-function: ease-in;
    -moz-animation-duration: 555;
}
ezanker
  • 24,628
  • 1
  • 20
  • 35
  • Thank you ezanker! This is exactly the solution I needed... by the way.. I was going to ask you how to control the speed of the transition and you just read my mind! Great work!! Thank you again. – xzibit Feb 10 '14 at 19:28
  • I would like to also ask you if you know how to make the transition smoother in a way that when it starts fast it ends slow-motion. – xzibit Feb 10 '14 at 19:39
  • specially slideInLeft – xzibit Feb 10 '14 at 19:42
  • 2
    If you look at the actual animation CSS it defines only 2 frames 0% - start, 100% - end. You can copy this and add any number of frames between 0 and 100%. See this fiddle: http://jsfiddle.net/ezanker/PbqZC/1/ and look for css near bottom called slideInLeftEZ. I added a frame at 40%, but you can tweak to your desire... – ezanker Feb 10 '14 at 20:15
  • EXCELLENT!!! I finally achieved the desired transition for my app... Thank you for your help and continuos support! – xzibit Feb 10 '14 at 20:45
  • I noticed it and applied it right off the bat!! Thank you! – xzibit Feb 10 '14 at 21:26
  • Hi ezanker, have you ever tried implementing Morf.js for jquery mobile transitions? http://www.joelambert.co.uk/morf/ – xzibit Feb 11 '14 at 06:32
  • I have not. It looks like the easiest thing would be to use it as a generator and then paste the produced css keyframes into your stylesheet... – ezanker Feb 11 '14 at 13:59
  • I have tried it with no luck. You see the the easeinExpo and easeoutExpo are really pretty cool and smooth for slide transitions... the generated code is also quite too long I think... – xzibit Feb 11 '14 at 15:41
  • Hi ezanker, do you have by any chance happen to have a css code to recreate this transition using a custom transition on jquery mobile http://c2prods.com/Project-Tyson/ – xzibit Feb 11 '14 at 22:12
  • Not exactly, but this might get you close: http://jsfiddle.net/ezanker/PbqZC/2/ just play around with the css to get what you want – ezanker Feb 11 '14 at 23:28
  • Hi ezanker, do you know anything about sending forms via AJAX. If you have some spare time, please take a look at this question I posted. http://stackoverflow.com/questions/21890185/submiting-a-form-from-a-single-page-webapp-using-ajax-call – xzibit Feb 27 '14 at 17:01