Solved

Jquery flip animation or fade animation help

Posted on 2014-03-03
7
551 Views
Last Modified: 2014-04-01
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
Comment
Question by:Pdesignz
  • 4
  • 3
7 Comments
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39902733
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
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39902741
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
 

Author Comment

by:Pdesignz
ID: 39902991
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39903003
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
 

Author Comment

by:Pdesignz
ID: 39903010
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
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39903836
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
 

Author Closing Comment

by:Pdesignz
ID: 39970256
Great Work! Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now