Rok*_*jan 36
只是一个简单的方法:
$("[data-typer]").attr("data-typer", function(i, txt) {
var $typer = $(this),
tot = txt.length,
pauseMax = 300,
pauseMin = 60,
ch = 0;
(function typeIt() {
if (ch > tot) return;
$typer.text(txt.substring(0, ch++));
setTimeout(typeIt, ~~(Math.random() * (pauseMax - pauseMin + 1) + pauseMin));
}());
});Run Code Online (Sandbox Code Playgroud)
/* PULSATING CARET */
[data-typer]:after {
content:"";
display: inline-block;
vertical-align: middle;
width:1px;
height:1em;
background: #000;
animation: caretPulsate 1s linear infinite;
-webkit-animation: caretPulsate 1s linear infinite;
}
@keyframes caretPulsate {
0% {opacity:1;}
50% {opacity:1;}
60% {opacity:0;}
100% {opacity:0;}
}
@-webkit-keyframes caretPulsate {
0% {opacity:1;}
50% {opacity:1;}
60% {opacity:0;}
100% {opacity:0;}
}Run Code Online (Sandbox Code Playgroud)
<span data-typer="Hi! My name is Al. I will guide you trough the Setup process."></span>
<h3 data-typer="This is another typing animated text"></h3>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
所以基本上jQuery获取data-text你的元素,逐个字符地插入,并且脉冲"插入符号"不是:after该SPAN 的CSS3动画元素.
| 归档时间: |
|
| 查看次数: |
15502 次 |
| 最近记录: |