Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
    <div class="foo">Mensaje 1</div>
    <div class="foo">Mensaje 2</div>
    <div class="foo">Mensaje 3</div>
    
    <button id="bar">Avanzar</button>
</body>
</html>
 
.foo{
    width: 100px;
    height: 25px;
    text-align: center;
    line-height: 25px;
    position: absolute;
    opacity: 0;
    transition: .15s;
}
.foo:nth-child(1){
    background: aquamarine;
}
.foo:nth-child(2){
    background: lightsteelblue;
}
.foo:nth-child(3){
    background: lightcyan;
}
#bar{
    float: right;
}
 
document.addEventListener("DOMContentLoaded", function(){
    var button = document.querySelector("#bar"),
        divs = document.querySelectorAll(".foo"),
        total = divs.length,
        count = 0;  
    
    //Solo la primera vez
    divs[count].style.opacity = 1;
    
    //Al pulsar el botón
    button.addEventListener("click", function(){
        if (count++ < total - 1){
            divs[count - 1].style.opacity = 0;
            divs[count].style.opacity = 1;
        }
        else{
            alert("Has llegado al final");
        }
    }, false);
}, false);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Alexis88pro
0viewers