Jquery animate toggle

I am trying to create an animation effect as shown below.

// JavaScript Document
$(document).ready(function () {
    $('.lovebtn').click(function () {
        $('.love').animate({
            height: '672px'
        }, 1000, function () {
            $('.lovetxt').css("display", "block");
            $(".lovebtn .button").attr("src", "images/btn_love_close.gif");

        });

    });


    // Lust
    $('.lustbtn').click(function () {
        $('.lust').animate({
            height: '672px'
        }, 1000, function () {
            $('.lusttxt').css("display", "block");
            $(".lustbtn .button").attr("src", "images/btn_lust_close.gif");

        });

    });


    //luxuary
    // Lust
    $('.luxurybtn').click(function () {
        $('.maskbg').css("display", "block");
        $('.luxury').animate({
            height: '1056px'
        }, 1000, function () {
            $('.luxurytxt').css("display", "block");
            $(".luxurybtn .button").attr("src", "images/btn_luxury_close.gif");

        });

    });
});

http://uniquedl.com/3closets/index.html

when you go to the ablove page and press the three buttons on love lust and luxury. you get a number of effects. when I press the same button, I will not change the effect.

any hints how can i do this?

+3
source share
3 answers

I will show only for the love button almost the same for other just different heights and CSS selectors, of course

$('.lovebtn').click(
     $('.love').toggle(  
         function() {  
             $('.love').animate({  
                 height: '672px'   
             }, 1000, function () {  
                 $('.lovetxt').css("display", "block");  
                 $(".lovebtn .button").attr("src", "images/btn_love_close.gif");  
             }    
        },    
        function() {    
            $('.love').animate({    
                height: '480px'    
            }, 1000, function () {    
                $('.lovetxt').css("display", "none");  
                $(".lovebtn .button").attr("src", "images/btn_love_open.gif");  
            }    
        }  
    );  
);

Sorry, I have problems placing the code in the correct layout :( You can check it here http://jsfiddle.net/dKyku/

, , , , / .

+6

, ,

   $('.lovebtn').click(function (){
   if (!$(this).hasClass('reverse')) {
    hasClickedLove = true;
    $('.love').animate({
        height: '672px'
    }, 1000, function () {
        $('.lovetxt').css("display", "block");
        $(".lovebtn .button").attr("src", "images/btn_love_close.gif");
    });
  $(this).addClass('reverse);

 }//end if
 else if(hasClass('reverse')) {
    $(this).removeClass('reverse);
    //animation code
   }
});
+5

Insert a boolean value, for example:

$('.lovebtn').click(function () {
    if ( !hasClickedcLove) {
        hasClickedLove = true;
        $('.love').animate({
            height: '672px'
        }, 1000, function () {
            $('.lovetxt').css("display", "block");
            $(".lovebtn .button").attr("src", "images/btn_love_close.gif");
        });
    }//end if
    else {
        hasClickedLove = false;
        //animation code
    }
});
+4
source

Source: https://habr.com/ru/post/1792219/


All Articles