Как заставить старый текст скользить вниз при добавлении нового текста над ним? - PullRequest
0 голосов
/ 16 марта 2020

Я передаю текст в div сверху.

Следующий код дает новейшему абзацу анимацию скольжения при добавлении его в div.

Как сделать, чтобы все абзацы скользили вниз при создании нового? Кроме того, любые советы по моему коду будут с благодарностью!

HTML:

<div id="text">

Javascript:

function addText(message) {
    var el = document.getElementById('text');
    var p = document.createElement('p');
    p.appendChild(document.createTextNode(message));
    el.insertBefore(p, el.childNodes[0] || null);
    $(p).addClass("reveal");
}

CSS:

.reveal {
    animation: slide-down 1s;
}

@keyframes slide-down {
  from {
    -moz-transform: translateY(-50px);
    -webkit-transform: translateY(-50px);
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    opacity: 1;
    -moz-transform: translateY(0px);
    -webkit-transform: translateY(0px);
    transform: translateY(0px);
    -moz-animation: linear;
    -webkit-animation: linear;
    animation: linear;
  }
}

1 Ответ

0 голосов
/ 16 марта 2020

Можете ли вы попробовать это.

function addText(message) {
     $('p').removeClass("reveal");
     setTimeout(function(){ 
        var el = document.getElementById('text');
        var p = document.createElement('p');
        p.appendChild(document.createTextNode(message));
        el.insertBefore(p, el.childNodes[0] || null);
        $('p').addClass("reveal");
     }, 500);
}
addText('Welcome to first paragrap');

Затем вы вызываете второго в консоли.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...