Created
August 24, 2018 21:21
-
-
Save olegpolyakov/14cb565602c04fd369ffa93d7400b98b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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