2017-02-14 136 views

回答

2

之前指定动画的一类,然后给该元素,您更新innerHTML

var name = 'somebody'; 
 
    el = document.getElementById("name"); 
 

 
el.innerHTML = name; 
 
el.classList.add('type');
body { 
 
    background: #171717; 
 
} 
 

 
p { 
 
    color: lime; 
 
    font-family: "Courier"; 
 
    font-size: 20px; 
 
    margin: 10px 0 0 10px; 
 
    white-space: nowrap; 
 
    overflow: hidden; 
 
    width: 30em; 
 
} 
 

 
.type { 
 
    animation: type 4s steps(60, end); 
 
} 
 

 
@keyframes type{ 
 
    from { width: 0; } 
 
}
<p id="name"></p>

+0

如何,如果我想在结果褪色后的文字动画类? – Rian

+0

完成,我得到它如何淡入。非常感谢您的帮助 – Rian

+0

@Rian awesome,np –