0

I am trying to animate this section of my portfolio page:

enter image description here

I would like for each of those 5 bars to light up one at a time.

Here are is the relevant code for this:

HTML:

<div class="row">
    <div class="col-lg-12 skill-item">
        <div class="row">
            <div class="col-lg-2"><i class="devicon-html5-plain-wordmark"></i></div>
            <div class="col-lg-10">
                <div class="row">
                    <div class="col-lg-12 skill-bar">
                        <div class="row">
                            <div class="col-lg-2 skill-rank-inactive"></div>
                            <div class="col-lg-2 skill-rank-inactive"></div>
                            <div class="col-lg-2 skill-rank-inactive"></div>
                            <div class="col-lg-2 skill-rank-inactive"></div>                                    
                            <div class="col-lg-2 skill-rank-inactive"></div>                                    
                        </div>
                    </div>
                    <div class="col-lg-12 skill-level">
                        HTML5
                    </div>
                </div>
            </div>
        </div>
    </div>

SCSS:

.skill-rank-inactive {
    background: white;
    border: 2px solid white;
    height: 3vh;
    transition: all 2s;
}

#back-end { 
    .skill-rank-active {
        background: $green;
        border: 2px solid white;
        height: 3vh;
    }

    i {
        color: $green;
    }
}

#front-end {
    .skill-rank-active {
        background: $blue-bright;
        border: 2px solid white;
        height: 3vh;
        transition: all 2s;
    }

    i {
        color: $blue-bright;
    }
}

Javascript:

$('#skills-page').bind('inview', function() {
    $('.skill-rank-inactive').addClass('skill-rank-active');
    $('.skill-rank-inactive').removeClass('skill-rank-inactive');
});

Is there a way to add 500ms delay between the transition of each "skill-rank" on the page? There would be multiple skills such as PHP, CSS, etc... I'd like for each skill to start at the same time, ie. the first rank for each skill starts then 500ms the next rank all the way up.

5
  • 1
    CSS animation seems like a better choice. Commented Jul 18, 2017 at 16:38
  • Will that allow me to delay each block separately? Commented Jul 18, 2017 at 16:48
  • 1
    you should look at queuing animations api.jquery.com/queue Commented Jul 18, 2017 at 16:51
  • animation-delay Commented Jul 18, 2017 at 17:00
  • Since blocks never light up at the same time, you actually only need one extra element that blinks on top of each block in turn! Saves the headache of queuing animations. Commented Jul 18, 2017 at 20:18

5 Answers 5

1

I decided to take the approach found on this website:

https://fabriceleven.com/design/creating-fancy-css3-fade-in-animations-on-page-load/

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

Comments

1

A solution without javascript: Have the 5 elements remain unchanging. Then have a single element (I'll use the pseudo :after element) which moves to cover each in turn, and as it is covering it briefly illuminates.

// No javascript needed! :D
@keyframes moving-light {
  0% { margin-left: 1%; }
  80% { margin-left: 81%; }
  100% { margin-left: 81%; }
}
@keyframes blinking-light {
  0% { opacity: 0; }
  65% { opacity: 1; }
  100% { opacity: 0; }
}

.lightup {
  position: relative;
  width: 100%; height: 30px;
  font-size: 0; /* Get rid of any inline spaces between elements */
}
.lightup > .box {
  display: inline-block;
  width: 18%; height: 100%;
  margin-left: 1%; margin-right: 1%;
  background-color: #a00000;
}
.lightup:after {
  content: "";
  position: absolute;
  display: block;
  width: 18%; height: 100%;
  left: 0; top: 0;
  background-color: #ff4040;
  opacity: 1;
  
  animation:
    5s steps(4, end) infinite moving-light,
    1s ease-out infinite blinking-light;
}
<div class="lightup">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>

Comments

0

You can use the setTimeout function to delay something

//delay by 500ms

setTimeout( do_something_here, 500); 

4 Comments

setTimeout Is not a JQuery function. It is a function that comes by default in the browser
setTimeout is not jQuery's.
Ah my mistake..but still, you can use it with jquery
The issue isn't really literally how to delay, but how to rewrite my javascript so that there is a place to put the code to delay.
0

Give all divs a common class like skills Then call a .each on them with a 500 ms delay.

The jQuery function should look something like this:

$('.skills').each(function(){
   setTimeout( $(this).removeClass('skill-rank-inactive'),500);
)}

Call this function on document.ready() or on an event.

Comments

0

you can use a loop with setTimeout()

$('#skills-page').bind('inview', function() {

    var delay = 0;

   $.each( $('.skill-rank-inactive'), function(){
        var element = $(this);
        setTimeout(function(){
            element.addClass('skill-rank-active')
            element.removeClass('skill-rank-inactive');
        },delay);

        delay += 500;
    });

});

I know that setTimeout is not jquery but the question has been:

"Is there a way to add 500ms delay between the transition of each "skill-rank" on the page?"

Comments

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.