0
People wanted to know a way to stop writing on the screen when you arrived at the last text within an array, I improved the code of the Simon Shahriveri see now 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>
<p id="write">Please wait, loading...
<p>
It was adapted for the VueJS
as a directive
but at that moment the binding.value
not in use and I wanted how can I stop the effect made by the loop setTimeout
saying that as soon as he writes the last text he stops.
well that only in the last text it was visible than being erased by
isDeleting
– iLeonardo Carvalho