Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Card flip animation Internet Explorer 11

I am trying to make a card flip and show its backside. It works in all other browsers but not in Internet Explorer 11.

I've tried adding -ms- prefaces, but that didn't help. The problem seems to be that IE does not support the css attribute transform-style: preserve-3d.

Here is a jsfiddle: https://jsfiddle.net/gbkq94hr/

HTML

<body>
    <article>
        <div id="card0" class="card">
            <figure class="front">
            </figure>
            <figure class="back">
            </figure>
        </div>
    </article>
</body>

JS

$(document).ready(function () {
    var flipped = false;
    var card = $("#card0");
    card.click(function() { flipFunction();});

    function flipFunction() {
        if (flipped) {
            flipped = false;
            card.removeClass('flip');
        } else {
            card.addClass('flip');
            flipped = true;
        }
    };
});

CSS

html {
    height: 100%;
}

.flip {
    transform: rotateY(180deg);
}

.card {
    float:left;
    width: 110px;
    height: 139px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 1s;
    position: relative;
}

figure {
    margin: 0;
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -ms-backface-visibility:hidden;
}

.back {
    background-color: blue;
    transform: rotateY(-180deg);
}

.front {
    z-index: 2;
    background-color: red;
    transform:rotateY(0deg);
}

article {
    height: 114px;
    width: 114px;
    perspective: 1000;
}

EDIT:

As suggested in the comments, I tried following David Walshes instructions, but still couldn't get it to work. https://jsfiddle.net/w9o2chmn/2/

like image 829
Waltari Avatar asked May 06 '16 06:05

Waltari


1 Answers

Hi I changed the jQuery code to perform card flip on click. Kindly check https://jsfiddle.net/w9o2chmn/6/

HTML I added class flip-container to article tag

<article class="flip-container">
    <div id="card0" class="card">
        <figure class="front">
        front
        </figure>
        <figure class="back">
        back
        </figure>
    </div>
</article>

CSS I have removed the CSS :hover code and placed it in jQuery click

/* entire container, keeps perspective */
.flip-container {
    perspective: 1000;
    transform-style: preserve-3d;
  color:#fff;
}

/*  UPDATED! flip the pane when hovered */
    /*.flip-container:hover .back {
        transform: rotateY(0deg);
    }
    .flip-container:hover .front {
        transform: rotateY(180deg);
    }*/

.flip-container, .front, .back {
    width: 200px;
    height: 200px;
}

/* flip speed goes here */
.card {
    transition: 0.6s;
    transform-style: preserve-3d;

    position: relative;
}

/* hide back of pane during swap */
.front, .back {
    backface-visibility: hidden;
    transition: 0.6s;
    transform-style: preserve-3d;

    position: absolute;
    top: 0;
    left: 0;
}

/*  UPDATED! front pane, placed above back */
.front {
    z-index: 2;
    transform: rotateY(0deg);
  background:red;
}

/* back, initially hidden pane */
.back {
    transform: rotateY(-180deg);
  background:blue;
}

/* 

jQuery

$(document).ready(function() {
    var flipped=false;

    $('.flip-container').on('click', function(){
        if(!flipped){
      $('.back').css('transform','rotateY(0deg)');
      $('.front').css('transform','rotateY(180deg)');
      flipped=true;
      console.log('true part :'+flipped);
      }
      else{
        $('.back').css('transform','rotateY(180deg)');
      $('.front').css('transform','rotateY(0deg)');
      flipped=false;
      console.log('else part :'+flipped);
      }
    });


});

Kindly let me know if its working for you...

PS: I tested this on IE11 and its working for me

like image 116
RRR Avatar answered Oct 05 '22 16:10

RRR