Skip to content

Instantly share code, notes, and snippets.

@olegpolyakov
Created August 24, 2018 21:21
Show Gist options
  • Save olegpolyakov/14cb565602c04fd369ffa93d7400b98b to your computer and use it in GitHub Desktop.
Save olegpolyakov/14cb565602c04fd369ffa93d7400b98b to your computer and use it in GitHub Desktop.
'use strict';
var subjects = ['программирование', 'веб-разработку', 'HTML', 'CSS', 'JavaScript', 'React', 'Angular', 'Node.js'];
var element = $('#hero .subject');
var subjectIndex = 0;
(function printSubjects() {
printSubject(subjects[subjectIndex])
.then(function() {
var timeout = setTimeout(function() {
element.text(' ');
subjectIndex === (subjects.length - 1) ? subjectIndex = 0 : subjectIndex += 1;
clearTimeout(timeout);
printSubjects();
}, 1000);
});
})();
function printSubject(subject) {
return new Promise(function(resolve) {
var index = 0;
var interval = setInterval(function() {
element.append(subject[index]);
index += 1;
if (index > subject.length) {
clearInterval(interval);
resolve();
}
}, 200);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment