1

I have created a Jquery toggle class function which adds and removes the class flipped on a click eventListner. click here. At the moment this function is working when the user clicks on any of the elements wrapped in the .card class. I when want to restrict where the user can click, therefore only allow the click function to work when the user clicks the .active-btn.

I have made attempts to do this however once the card is flipped the active-btn class doesn't seem to work. by the looks of things the 'front div' is sitting on top of the 'back div Below is a snippet of my code …

$('.active-btn').click(function(e){
             e.preventDefault();
            $card = $(this).closest('.card');
            $('.flipped').not($card).removeClass('flipped');
            $card.toggleClass('flipped');
        });
NewBoy
  • 1,124
  • 2
  • 17
  • 40

3 Answers3

0

I basically change the z-index to -1 on .flip .card .face, and

.flip .card {
  -webkit-transform-style: flat;
}

The problem with your original is that the perserved-3d keep changing the z-index which causing issues with the order.

z-index is canceled by setting transform(rotate)

Here is the post which goes in more detail.

Community
  • 1
  • 1
stanley1943
  • 865
  • 1
  • 7
  • 15
  • global-padding: display: none; hides everything – NewBoy Sep 07 '15 at 08:27
  • meh i don't think that's the case. maybe the case on the prototype i put on jsfiddle but defiantely not the case with the code i have on my local server… the 'front div' is sitting on to of the 'back div' thanks anyway – NewBoy Sep 07 '15 at 08:33
  • front div' is sitting on top of the 'back div' – NewBoy Sep 07 '15 at 09:08
  • I think I know the issue. If you flip the card, the transform rotate breaks the z-index which makes the "back" comes forward. http://jsfiddle.net/rcbayy5x/10/ is that something you are looking for? – stanley1943 Sep 07 '15 at 09:55
  • did you apply position absolute to the front div ? – NewBoy Sep 07 '15 at 10:14
0

You need to use the toggle element, right now the active btn will remove the class and won't add it after.

Do it like this:

$( ".active-btn" ).toggle(function() {
    e.preventDefault();
            $card = $(this).closest('.card');
            $('.flipped').not($card).removeClass('flipped');
            $card.toggleClass('flipped');
}, function() {
    e.preventDefault();
            $card = $(this).closest('.card');
            $('.flipped').not($card).addClass('flipped');
            $card.toggleClass('flipped'); );
});
Barr J
  • 10,636
  • 1
  • 28
  • 46
0

use !hasClass (class has not exist) rather than not,

$('.active-btn').click(function(e){
         e.preventDefault();
        $card = $(this).closest('.card');
       if (!$('.flipped').hasClass($card)) {
                 removeClass('flipped');
                 $card.toggleClass('flipped');
            }
    });
Jack jdeoel
  • 4,554
  • 5
  • 26
  • 52