简体   繁体   中英

How to increase the value of a variable by 100?

I have an ACF repeater through which I output cards. Added spawn animation to cards. I need an animation delay of 100 more than the previous one for each card. How can i do this?

 <ul data-aos="zoom-in" class="cards-list"> <?php if (have_rows('cards')): while (have_rows('cards')): the_row(); $delay = 300; ?> <li data-aos-delay="<?php echo $delay?>"> <img src="<?php the_sub_field('card_icon'); ?>" alt=""> <h3> <?php the_sub_field('card_title'); ?> </h3> <p> <?php the_sub_field('card_text'); ?> </p> </li> <?php endwhile; endif; ?> </ul>

You can define the initial value of $delay outside your while loop, then increment it within the loop:

<?php if (have_rows('cards')) :
     $delay = 200;
     while (have_rows('cards')) : the_row();
       $delay += 100; ?>

Note the initial value of 200 instead of 300, because it will be incremented by 100 for the first card as well to ensure that has the initial delay of 300.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM