Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let myText = ["Webdeveloper", "React Developer"]; //my input text
- let count = 0; //initially count is 0 it will trace the input text index number
- let currentText = ''; //here my current text will store
- let strIndx = 0; //it will track the slice part of string index
- let arrayTrack = 0; //this will tract the array ittaration so that if the array is empty auto call function will stop
- let trackTheElement = 1 //to execute the reverse split of string index number
- let loop = true //do the loop running or run only one time.if true then loop will running and if false then loop will run only one time
- // let sliceOfString = myText[0].split("")[0]
- let sliceOfString
- const hello = () => {
- currentText = myText[count] //store the current text
- let currentTextLength = currentText.length //store the current text length
- if(currentTextLength >= trackTheElement){ //check the current text is greater than track element or not
- sliceOfString = currentText.slice(0, ++strIndx) //slice one by one string incremently
- if(myText.length >= count + 1 ){ //check the main input text array length is greter and equal to the count number
- trackTheElement++
- }
- console.log(sliceOfString);
- }else if(currentTextLength < trackTheElement){
- sliceOfString = currentText.slice(0, --strIndx) //slice one by one string decremently
- if(myText.length >= count + 1 ){ //check the main input text array length is greter and equal to the count number
- if(sliceOfString.length == 0){ //if the slice string's length is zero then it will execute to continue another text and did the same animation
- count++
- strIndx = 0
- trackTheElement = 0
- arrayTrack++
- if(myText.length == count && sliceOfString.length == 0 ){ //for continue the loop start from the begging
- count = 0
- }
- }
- trackTheElement++
- // console.log(sliceOfString);
- }
- console.log(sliceOfString);
- }
- // call the function part
- if(arrayTrack <= myText.length - 1){
- setTimeout(() => hello(), 350)
- }else{
- loop && setTimeout(() => hello(), 350) //if the loop is true then it will looping these process
- }
- };
- hello()
Add Comment
Please, Sign In to add comment