While I realise I’m posting to a 3 year old question, I find myself needing the exact same help. Jim, if you figured it all out, would you be so kind as to maybe share your code? I’m clueless, even after reading and watching video tutorials.
let i = 0;
let myText = ["this", "that", "they", "these"];
let duration = 2000;
$w.onReady(function () {
//Set a default text or write from the editor because this will come out first
$w('#textbox1').text = myText[0];
setInterval(()=>{
changeText()
}, duration)
});
function changeText(){
$w("#textbox1").text = (myText[i]).toString();
if(i < myText.length - 1){
i++;
} else {
i = 0;
}
}
const texts = ['text1', 'text2'/*...add more if needed*/];
let i = 0;
const intervalInMilliseconds = 4000;
function changeText(){
$w('#text1').text = texts[i];
i = (i + 1) % texts.length;
}
$w.onReady(() => setInterval(changeText , intervalInMilliseconds));
@gelecegiyazmak Thank you kindly for the help Erdem, please forgive my ignorance, as I don’t have any coding fundamentals and know how. I’ve looked at the code you’ve provided me, and replaced the “textbox1” to the ID I have, which is “#speech1”. From there, I’m lost. And I get this error: “ReferenceError: changeText is not defined”
@jonatandor35 Brilliant, with your code, I got it working A million and one thanks for your help JD, and to Erdem… lovely to see a community of friendly and helpful people. Hope to be apart of that one day where I can contribute back. Cheers guys!!!
@jonatandor35 I notice that the textbox settings, Ie: font type, size, color, etc… do not change and are not affected by the changes I make through the “box settings”, because the text is within the const texts = … Is there anyway to control any of those text attributes through the code? For example, if I needed just to add bold to the text, would that be possible? Many thanks again!
@valym777 it is possible to set different styling for the different texts. With html tags
For example:
const texts = ['<p>text1 regular</p>', '<p style="color:red">text2 <b>this is bold</b></p>'/*...add more if needed*/];
let i = 0;
const intervalInMilliseconds = 4000;
function changeText(){
$w('#text1').html = texts[i];
i = (i + 1) % texts.length;
}
$w.onReady(() => setInterval(changeText , intervalInMilliseconds));
You can add font-family/alignment/font-size etc. to the styling.
@jonatandor35 I owe you a couple of beers (At least ) Thank you so much for taking the time, for not only answering, but giving me the exact answer I need, so I can understand how the code works. I’ve implemented it, works like a dream. The site is still under development (design wise), but here’s a little captured video to see the code in action… Thanks again J.D.