how to flip a div using jquery and css?

<html>
<style>
.panel
{
height:300px;
width:280px;
margin-left:850px;
margin-top:150px;
position:absolute;
-webkit-perspective:600px;
-moz-perspective:600px;
}
.panel .front
{
top:0;
z-index:900;
height:inherit;
width:inherit;
position:absolute;
text-align:center;
-webkit-transform:rotateX(0deg) rotateY(0deg);
-webkit-transform-style:preserve -3d;
-webkit-backface-visibility:hidden;
-moz-transform:rotateX(0deg) rotateY(0deg);
-moz-transform-style:preserve -3d;
-moz-backface-visibility:hidden;
-o-transition: all.4s ease-in-out;
-ms-transition: all.4s ease-in-out;
-moz-transition: all.4s ease-in-out;
-webkit-transition: all.4s ease-in-out;
transition: all.4s ease-in-out;
}
.panel.flip .front
{
z-index:900;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);

}
.panel .back
{
top:0;
z-index:800;
height:inherit;
width:inherit;
position:absolute;
-webkit-transform: rotateY(-180deg);
-webkit-transform-style:preserve -3d;
-webkit-backface-visibility:hidden;
-moz-transform: rotateY(-180deg);
-moz-transform-style:preserve -3d;
-moz-backface-visibility:hidden;
-o-transition: all.4s ease-in-out;
-ms-transition: all.4s ease-in-out;
-moz-transition: all.4s ease-in-out;
-webkit-transition: all.4s ease-in-out;
transition: all.4s ease-in-out;
}
.panel.flip .back
{
z-index:1000;
-webkit-transform: rotateX(0deg) rotateY(0deg);
-moz-transform: rotateX(0deg) rotateY(0deg);

}
.pad1
{
height:300px;
width:280px;
background-color:yellow;
}
.pad2
{
height:300px;
width:280px;
background-color:yellow;
}
</style>
<script type="text/javascript">
var i=0;
if(i==0)
{
$(document).ready(function(){
$("#trail").click(function(){
$('.panel').addClass('flip'); i++;

});
});
}
if(i==1)
{
$(document).ready(function(){
$("#trail").click(function(){
$('.panel').removeClass('flip'); i--;

});
});
}
</script>
<body>
<div class="panel">
<div class="front">
<div class="pad1">
</div>
</div>
<div class="back">
<div class="pad2"
</div>
</div>
</div>

<div id="trail" style="height:50px; width:50px; position:absolute; margin-left:200px; margin-top:350px; background-color:red;">
</div>
</body>
</html>
the problem is the remove class part is not functioning. what to do????

1 answer

1 accepted

4 votes
Accepted answer
Sean Curtis Atlassian Team Jul 20, 2013

Not sure if this will work but your JS is way more than you need. Try this instead;

$(function() {
  $('#trail').click(function() {
    $('.panel').toggleClass('flip');
  });
});

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Agile

How Scrum works? It starts with training and education

To answer “How scrum works,” most of the teams I've worked with first addressed the question: “where to start?”  That question applies to both implementation and improvements on the Scrum framew...

233 views 3 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you