A
A
Aljo2021-07-19 05:38:34
JavaScript
Aljo, 2021-07-19 05:38:34

How to change events after the first click?

Hello!
How to make it so that on the first click one cycle is performed, and on the subsequent ones another?

$(".products-toggle").click(function(e) {
        e.preventDefault();
       //первый цикл
        productsRow = $(this).parent().siblings('.products-row');        
         if(productsRow .hasClass("shown")) {
            productsRow .animate({"height": "50px"}).removeClass("shown");
         } else {
            productsRow .animate({"height": "auto"}).addClass("shown");
            animateHeight = productsRow .height();
         } 
        //после первого выполнять это    
         if(productsRow .hasClass("shown")) {
            productsRow .animate({"height": "50px"}).removeClass("shown");
         } else {
            productsRow .animate({"height": animateHeight }).addClass("shown");
         } 
    });


Why do I need it. I want to record the height of the products-row block with height: auto. It's just that if you set a fixed height, then blocks with a small number of products will have a large empty space.
If there is any better solution, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Dubrovin, 2021-07-19
@aljo222

Add the data attribute to the element.
If there is nothing in it, the launch of 1 logic
If there is a launch of the 2nd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question