JSFiddle - React, Tailwind, and code Playground
HTML
<button type="button">Mostrar mais</button>
CSS
.MSGR {
height: 20px;
transition: all .5s;
}
.hidden {
height:0;
opacity:0;
}
JavaScript
var divs = [];
// pedaço para montar conteudo
for (var i = 0; i <= 20; i++) {
var div = document.createElement('div');
div.innerHTML = 'Linha ' + i;
div.classList.add('MSGR', 'hidden');
document.body.appendChild(div);
divs.push(div);
}
// função que retira a classe hidden
function mostrarDesde(elementos, indice, qtd) {
if (!qtd) qtd = 2; // no caso de um dia queres mudar quantas mostra cada vez
for (var i = indice; i < indice + qtd; i++) {
if (elementos[i]) elementos[i].classList.remove('hidden');
}
}
var indiceVisivel = divs.length - 2;
mostrarDesde(divs, indiceVisivel);
document.querySelector('button').addEventListener('click', function () {
mostrarDesde(divs, indiceVisivel = indiceVisivel - 2);
if (indiceVisivel < 0) this.classList.add('hidden');
});