2016-05-06 91 views
9

我正在嘗試製作卡片翻轉並顯示其背面。它適用於所有其他瀏覽器,但不適用於Internet Explorer 11.卡片翻轉動畫Internet Explorer 11

我試着添加-ms-序言,但沒有幫助。問題似乎是IE不支持css屬性transform-style: preserve-3d

這裏是一個的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; 
} 

編輯:

正如評論中所建議的那樣,我試着遵循David Walshes的指示,但仍然無法使其工作。 https://jsfiddle.net/w9o2chmn/2/

+1

請參閱https://davidwalsh.name/css翻轉它可能有幫助 – RRR

+0

這可以工作,但我不能讓它在按鈕點擊工作。 :/ – Waltari

+0

請檢查我的回答 – RRR

回答

3

嗨我更改了jQuery代碼來執行卡片翻轉點擊。請檢查https://jsfiddle.net/w9o2chmn/6/

HTML 我添加類flip-container到商品標籤

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

CSS 我在的jQuery刪除CSS :hover代碼,並把它放在單擊

/* 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); 
     } 
    }); 


}); 

請讓我知道,如果它爲你工作...

PS:我測試了在IE11和工作對我來說

+3

jsFiddle在IE11中不適合我。我在Windows 10上 – nebulousGirl

+0

這非常棒,適用於IE11,Opera,Firefox和Chrome,但在Safari中,動畫看起來很奇怪。它看起來像一半是紅色,一半是藍色。任何想法如何解決它? –

+0

在Windows 10上的ie11上不起作用,僅在Windows 8上 –