I'm working on a card game and making a simple flip effect. I have stuck with a CSS rotating.
This code without rotation work good:
$(document).ready(function() {
var card = $("#card");
var width = card.width();
var height = card.height();
var left = card.offset().left;
var top = card.offset().top;
card.delay(500).animate({
"width" : "0px",
"height" : height+"px",
"left" : "+="+(width / 2)+"px"
}, 1000, function() {
$(this).css('background-color', '#ff0000').animate({
"width" : width+"px",
"left" : "-="+(width / 2)+"px"
}, 1000);
});
});
https://jsfiddle.net/Lo8egkra/1/
But if I add rotation:
$(document).ready(function() {
var card = $("#card");
card.css({"transform": "rotate(90deg)"});
var width = card.width();
var height = card.height();
var left = card.offset().left;
var top = card.offset().top;
card.delay(500).animate({
"width" : "0px",
"height" : height+"px",
"left" : "+="+(width / 2)+"px"
}, 1000, function() {
$(this).css('background-color', '#ff0000').animate({
"width" : width+"px",
"left" : "-="+(width / 2)+"px"
}, 1000);
});
});
https://jsfiddle.net/Lo8egkra/2/
You can see. It changes its position and the width and height sizes and the flip effect is quite buggy. Probably I'm doing something wrong but I've tried to fix this for few hours and without success.