People wanted to know a way to stop typing on the screen when it arrived in the last text inside an array, I improved the Simon Shahriveri now see the code rewritten in jQuery:
'use strict';
var $self = $('#write');
var text = undefined ? binding.value.text : [$self.text()],
delay = undefined ? binding.value.delay : 100,
loopNum = 0,
i = loopNum % text.length,
fullTxt = text[i],
isDeleting = false,
txt = '',
delta = 200 - Math.random() * 100;
function txtType() {
if (isDeleting) {
txt = fullTxt.substring(0, txt.length - 1);
} else {
txt = fullTxt.substring(0, txt.length + 1);
}
$self.text('').text(txt);
if (isDeleting) delta /= 2;
if (!isDeleting && txt === fullTxt) {
delta = parseInt(delay, 10) || 2000;
isDeleting = true;
} else if (isDeleting && txt === '') {
isDeleting = false;
loopNum++;
delta = delay;
}
setTimeout(function () {
txtType();
}, delta);
}
// Run
$(document).ready(function () {
txtType();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pid="write">Please wait, loading...
<p>
It has been adapted to VueJS
as a directive
but at this time binding.value
is not in use and I wanted how can I stop the loop effect of setTimeout
saying that as soon as I type the last text it stops.