• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Jquery flip animation or fade animation help

Need help with jquery! I have six boxes developed with css and I would like to have a fade or flip animation that could then reveal additional content. Currently boxes are done in css, but not sure if need to be images to be able to have animation. My knowledge of jquery is minimal, so I would appreciate any help provided.

Example page and code can be founds here, http://www.pdesignz.com

Thanks
0
Pdesignz
Asked:
Pdesignz
  • 4
  • 3
1 Solution
 
Julian HansenCommented:
One of doing the fade is to have the div like so
    <li class="emotion">
      <div class="first">
        <img src="http://www.pdesignz.com/Images/emotion-icon.png">
        <h2>Emotional Involvement and a Positive Mental Attitude</h2>
      </div>
      <div class="second">
        <p>New content and the rest goes here blah blah blah. The rain in spain falls mainly on the empire state building is in New York City of the Ancients is featured on what famous TV is bad for you so don't watch it or you will trip over your own shoes were made for walking and that is what they do</p>
      </div>
    </li>

Open in new window

Then  JQuery
<script type="text/javascript">
$(function() {
  $('#value-boxes li').click(function() {
    $(this).find('div.first').fadeToggle(500);
    $(this).find('div.second').fadeToggle(500);
  });
});
</script>

Open in new window

Finally CSS
#value-boxes li {
  ...
  color: white;  /* ADD THIS */
}
.second {
  display: none;
  color: white;
}
#value-boxes li div {
  position: absolute;
  left: 0;
  top: 0;
}

Open in new window

Full listing attached

Working sample here
t579.html
0
 
Julian HansenCommented:
Explanation of previous post.

We put the two different views in their own div's which are then positioned absolutely within their container (the <li>). We do this because we want fading in while the other is fading out and if they are not absolutely positioned then they are going to push each other down as they each are in transition.

We then use the toggleFade function on each of the div's in the <li> to change state from one to the other.
0
 
PdesignzAuthor Commented:
Looks great in example, I implemented but when I toggle the fade it appears below the box for a split second and then jumps up. I am not sure if I missed something or not.

http://www.pdesignz.com

Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Julian HansenCommented:
Yup - that is why I made the content div's position: absolute; When I posted the updated styles I made an error and edited the wrong style. Style posting should have looked like this
#value-boxes li {
  ...
  position: relative; /* ADD THIS */
}
.second {
  display: none;
  color: white;
}
#value-boxes li div {
  position: absolute;
  left: 0;
  top: 0;
}

Open in new window

The reason it is jumping is because the container div's are effectively one below the other with the inactive one hidden. When the toggleFade fires both become visible as they transition, but because they are both position: relative the one appears below the other until the top one fades out at which point the bottom one jumps up.

By making the boxes position absolute it means that both boxes are positioned relative to the top left corner of the <li> container and as they each transition from hidden to visible and vice versa they maintain their positions relative to the parent <li> giving the impression of fading from one to the other.

You probably just need to add the position: relative to the #value-boxes li style (remove the color: white - that was an error.
0
 
PdesignzAuthor Commented:
OK, I missed the absolute...if I wanted to try a flip animation instead of a fade, how would I go about doing that?

Thanks
0
 
Julian HansenCommented:
You can do a CSS flip using the technique described here

http://davidwalsh.name/css-flip

Might not work on older browsers espectially IE

Here is a list of some Flip libraries that you could also look at.

http://www.jqueryrain.com/2012/08/jquery-flip-effect-plugin-examples/

Post back if you get stuck.
0
 
PdesignzAuthor Commented:
Great Work! Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now