Press 3 box at a time by clicking the button

Asked

Viewed 33 times

1

$(".box-hidden").slice(0, 3).show();

$("#loadMore").on('click', function (e) {

    e.preventDefault();

    $( ".box-hidden:hidden" ).first().fadeIn( "slow", function showNext() {
        $( this ).next( ".thumb-hidden:hidden" ).fadeIn( "slow", showNext );

    });

    if ($(".box-hidden:hidden").length == 0) {
        $("#load").fadeOut('slow');
    }

});
.wrap {
        margin: 100px;
        overflow: hidden;
        width: 600px;
        margin: auto;
    }

    .wrap .box {
        padding: 50px;
        background: #548614;
        float: left;
        margin: 10px;
        color: white;
    }

    .wrap .box-hidden {
        display: none;
    }

    .wrap-button {
        margin: auto;
        width: 120px;
        overflow: hidden;
         clear: both;
    }

    .wrap-button .btn-load {
        padding: 9px;
        display: block;
        color: #fff;
        background: #323232;
       
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrap">
        <div class="box box-hidden">
            <p>
                Content 1
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 2
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 3
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 4
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 5
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 6
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 7
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 8
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 9
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 1
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 2
            </p>
        </div>



        <div class="box box-hidden">
            <p>
                Content 3
            </p>
        </div>


        <div class="wrap-button">

            <a href="#" id="loadMore" class="btn-load">Carregar mais</a>

        </div>

1 answer

2

You can do it using the method eq() always setting 0, because every time it is searched in HTML the class .box-hidden, always returns the first (0) element:

$(".box-hidden").slice(0, 3).show();

$("#loadMore").on('click', function() {

  $(".box-hidden:hidden").eq(0).fadeIn("slow");
  $(".box-hidden:hidden").eq(0).fadeIn(1500);
  $(".box-hidden:hidden").eq(0).fadeIn(2500);
  
  var boxes = $(".box-hidden:hidden").length;
  
  if(boxes == 0) {
    $("#loadMore").hide();
  }

});
.wrap {
  margin: 100px;
  overflow: hidden;
  width: 600px;
  margin: auto;
}

.wrap .box {
  padding: 50px;
  background: #548614;
  float: left;
  margin: 10px;
  color: white;
}

.wrap .box-hidden {
  display: none;
}

.wrap-button {
  margin: auto;
  width: 120px;
  overflow: hidden;
  clear: both;
}

.wrap-button .btn-load {
  padding: 9px;
  display: block;
  color: #fff;
  background: #323232;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div class="wrap">
  <div class="box box-hidden">
    <p>Content 1</p>
  </div>

  <div class="box box-hidden">
    <p>Content 2</p>
  </div>

  <div class="box box-hidden">
    <p>Content 3</p>
  </div>

  <div class="box box-hidden">
    <p>Content 4</p>
  </div>

  <div class="box box-hidden">
    <p>Content 5</p>
  </div>

  <div class="box box-hidden">
    <p>Content 6</p>
  </div>

  <div class="box box-hidden">
    <p>Content 7</p>
  </div>

  <div class="box box-hidden">
    <p>Content 8</p>
  </div>

  <div class="box box-hidden">
    <p>Content 9</p>
  </div>

  <div class="box box-hidden">
    <p>Content 1</p>
  </div>

  <div class="box box-hidden">
    <p>Content 2</p>
  </div>

  <div class="box box-hidden">
    <p>Content 3</p>
  </div>

  <div class="wrap-button">
    <a href="#" id="loadMore" class="btn-load">Carregar mais</a>
  </div>

</div>

  • but that way he appears at 3 at a time, I would like to appear at 3 but appear 1 after the other and then the other, understood ?

  • With a delay from each other you say?

  • This, will display 3 per click, but do not display the 3 at once and yes 1 after the other and then the other

  • I edited the answer.

  • toooop bro! was just like that! thanks!!!!!!

  • Jewel that helped Johnny, consider accepting the answer so that your question is not as open on the site.

  • can help me with one more question - Leandrade ?

  • Can speak Johnny.

  • At the end of loading all images I would like to hide the button press more. how can I do this?

  • Simple this Johnny, I’ve already edited the answer with this feature too, ok!

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.