0

Here is the text animation I am doing: http://jsfiddle.net/4DJe6/

I want the animation to pause for a second so the user can read the full text in red once and then it should start:

Any suggestion how can I add a second pause??

Here is the code: HTML

<div><span id="black">Waiting for the task!</span><span id="red">Waiting for the task!</span></div>

CSS

#black{
    color:black;
    font-weight:bold;
    font-size:2em;
}
#red {
    position:absolute;
    z-index:10;
    left:0px;
    width:0px;
    overflow:hidden;
    font-weight:bold;
    font-size:2em;
    color:red;
    white-space:nowrap;
}

div {
    display: inline-block;
    position: relative;
}

html {
    text-align: center;
}

JS

var red = document.getElementById('red');
var black = document.getElementById('black');
red.style.width = "0px";
var animation = setInterval(function(){
    console.log(red.style.width);
    if(red.style.width == "288px")
    {  
     red.style.width = "0px";}

    red.style.width = parseInt(red.style.width,10)+1 +"px";},30);

Let me know if you need any other information.

Please suggest.

1

1 Answer 1

3

The following should do it:

var red = document.getElementById('red');
    red.style.width = "0px";
var black = document.getElementById('black');

// Add Var to Keep Track of Pause
var pauser = 0;

var animation = setInterval(function(){
    if(red.style.width == "288px"){
        pauser += 34; // Increase Pause

        // Pause is Greater Than 1s
        if (pauser >= 1000){
            red.style.width = "0px"; // Reset Animation
            pauser = 0; // Reset Pause
        }
    } else {
        red.style.width = parseInt(red.style.width,10)+1 +"px";
    }
}, 30);

Updated Fiddle Here.

I Hope this helps!

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

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.