views:

723

answers:

2

I am trying to make a flash card studying web app for a school project and I wanted to use Flip! I have an issue, though when I put the anchors with their click events bound to the flip function inside the divs to be flipped. I am new to jQuery. Any help would be appreciated. Is there a flip forum? My code is below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
  <title>Flippant</title>
  <script src="http://www.google.com/jsapi" type="text/javascript"></script>
  <script type="text/javascript">
    //<![CDATA[    
    google.load("jquery", "1.3.2");
    google.load("jqueryui", "1.7.2");
    //]]>
  </script>
  <script type="text/javascript" src="jquery.flip.js"></script>
  <script type="text/javascript">
  var f2b = function(){
    $("#card").flip({
      direction: 'tb',
      color: '#B34212',
      content: $('#back')
    });
  }

  var b2f = function(){
    $("#card").flip({
      direction: 'tb',
      color: '#B34212',
      content: $('#front')
    });
  }
  $(document).ready(function(){
    $("#flip1").click(f2b);
    $("#flip2").click(b2f);
    $("#flip2").click();
  });
  </script>
  <style type="text/css">
  .back { display: none; }
  .front { display: none; }
  </style>
</head>
<body>
  <div class="card" id="card"></div>
  <div class="front" id="front">
    This is <br />
    the front <br />
    of the card. <br />
    <a href="#" id="flip1" title="flip to back">Flip1</a>
  </div>
  <div class="back" id="back">
    This is<br />
    the back<br />
    of the card.<br /> 
    <a href="#" id="flip2" title="flip to front">Flip2</a>
  </div>
</body>
</html>
A: 

It appears the flip plugin destroys the event handlers that you set up on document ready. The way around it is to use live event binding. Change your document ready function to this:

$("#flip1").live('click', f2b);
$("#flip2").live('click', b2f);
$("#flip2").trigger('click');

Edit: I should also mention that the initial animation doesn't seem to fire unless you have specified a width in your CSS, like this:

.card { height: 200px; width:200px; }
Barnabas Kendall
A: 

Hey. I want to use this on one of my projects. I wanted to put the content in divs, and your question and the reply helped me do it. I used exactly what you guys wrote here. But I got a problem and don't know how to solve it. When the page first loads, the content automatically flips without clicking anything. But I don't want it to flip without clicking the flip link. What should I do? Thanks in advance.

JLee