0

I'm trying to convert a hover event for a degraded jquery flip piece of my script. I've done this for the css3d transform but I'm not sure how to convert the hover event for the degraded portion. Here is what I have so far:

if($("html").hasClass("csstransforms3d")){

    $('.card').click(function () {

        if ($(this).hasClass('flip')) {
            $(this).removeClass('flip');
        }
        else {
            $(this).addClass('flip');
        }
    });

    /*
    $('.card').hover(function(){
        $(this).addClass('flip');
    },function(){
        $(this).removeClass('flip');
    });
    */
} 
else{
    // How do I add a click event here instead of hover?
    $('.card').hover(function(){
        $(this).find(".front").animate({top: -190}, 'fast');
    },function(){
        $(this).find(".front").animate({top: 0}, 'fast');
    });
}   

How do I convert the hover event for a click event for the degraded section?

10
  • replace the word hover with click? Commented Aug 5, 2013 at 12:57
  • didn't you mean mousedown and mouseup? Commented Aug 5, 2013 at 12:57
  • replace 'hover' with 'click' Commented Aug 5, 2013 at 12:57
  • @raam86 no, won't work like this. Commented Aug 5, 2013 at 12:58
  • 1
    @raam86 because both callbacks will be called at once. OP is looking for toggle() event, i think, which is now removed: stackoverflow.com/questions/14338078/… Commented Aug 5, 2013 at 12:59

1 Answer 1

3

If you want to use click, you need to store a state value - you can use .data() to do it

Try something like

$('.card').click(function(){
    var $this = $(this);

    if($this.data('hidden')){
        $this.find(".front").animate({top: -190}, 'fast').data('hidden', false);
    } else {
        $this.find(".front").animate({top: 0}, 'fast').data('hidden', true);
    }

});
Sign up to request clarification or add additional context in comments.

2 Comments

Looks like a good solution but for some reason the data attribute isn't getting set...any thoughts?
I ended up setting the data attribute first and then checking the state but it's working...Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.