nnattawat / flip

A lightweight jQuery plugin to make 3D card flipping animation
Other
624 stars 312 forks source link

One flipped over at a time #55

Closed onlybrian closed 8 years ago

onlybrian commented 8 years ago

Is it possible to have one object flipped at a time? When one object is flipped, any other objects that were flipped, gets unflipped. Thanks

Download commented 8 years ago

Yes this should be possible. Easiest would probably be to set trigger to 'manual' and take matters into your own hands. You can detect whether a node is flipped or not by reading $('#your-element').data('flipped')

onlybrian commented 8 years ago

Cool, I got it to work, thanks. Although my javascript is rusty, here's what I did.

$(".element").on('flip:done', function() {
    var isFlipped = $(this).data('flipped');
    if (isFlipped) {
        $(this).parent().siblings().children().flip(false);
    }
});
Download commented 8 years ago

Great that you solved it and thanks for posting your solution!

Download commented 8 years ago

@JemarJones Your events being set to good use :)

JemarJones commented 8 years ago

This looks great! Though one thing here that I'm sort of wary of is relying on the data-flipped attribute in client code. This is sort of part of the internal representation rather than the API and is (in my mind) something that could be changed. I guess I hadn't really considered that data attributes are of course, public.

JemarJones commented 8 years ago

I suppose we could just consider those attributes as part of the API and make sure not to change them whilst moving forward.

Download commented 8 years ago

Or we could implement something like:

var isFlipped = $(this).flip('flipped');

The question is how much better that really is... Personally I think it's fine the way it is now.

JemarJones commented 8 years ago

I'm fine with leaving it the way it is (people may already be relying on it), and just making sure not to change it.