-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (20 loc) · 692 Bytes
/
index.js
File metadata and controls
23 lines (20 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function createTyper(str, identifier) {
const words = str.split('|')
const options = createOptions(1,words)
const toAttach = createElemAndAttachToParent(identifier)
const myTyper = new Typed(toAttach,options)
return myTyper
}
const createOptions = (spd,words) => ({
strings : words,
typeSpeed : spd ? spd : 0,
backSpeed : 1,
loop:true
})
function createElemAndAttachToParent(identifier){
const elem = document.createElement('span')
const parent = document.querySelector(identifier)
parent.appendChild(elem)
elem.setAttribute('id','' + identifier.split(/[.#]/)[1]+'-child')
return "#" + elem.getAttribute('id')
}