javascript for wixsite中的循环数组

javascript for wixsite中的循环数组,javascript,arrays,animation,text,velo,Javascript,Arrays,Animation,Text,Velo,我正试图在我的wixsite上获得一个单词“旋转门”的效果,结果却被下一个单词所取代 我在想这样做的方法是在javascript中有一个我想要出现的单词数组,然后循环通过该数组,使用我选择的文本动画将每个单词带到屏幕上 我有一段代码,可以把一个单词“打印”到我的wix网站上,但是我如何调整它,让它对许多单词都执行相同的操作,一个接一个地退出屏幕(几乎就像是在屏幕上打印单词的幻灯片一样?) 这是我的密码: > import wixData from 'wix-data'; > >

我正试图在我的wixsite上获得一个单词“旋转门”的效果,结果却被下一个单词所取代

我在想这样做的方法是在javascript中有一个我想要出现的单词数组,然后循环通过该数组,使用我选择的文本动画将每个单词带到屏幕上

我有一段代码,可以把一个单词“打印”到我的wix网站上,但是我如何调整它,让它对许多单词都执行相同的操作,一个接一个地退出屏幕(几乎就像是在屏幕上打印单词的幻灯片一样?)

这是我的密码:

> import wixData from 'wix-data';
> 
> let interval; let timeInterval = 350; let typeStr = "Invest"; let
> typeIdx; let htmlStr = ''; let displayStr;
> 
> $w.onReady(function () {

// Get the original html string, and split it into two pieces.
// In the process, remove the separator !##!
// By saving the original html, we preserve the style of the text to display.
if (htmlStr.length === 0) { // just get the original html text the first time
    htmlStr = $w("#typewriterPage").html;
}
$w("#typewriterPage").html = ''; // don't show the original text
let strPieces = htmlStr.split("!##!");

displayStr = ''; // init string that we will "type" to
typeIdx = 0; // start at beginning of string we want to "type"

// Declare an interval function that will run in the background.
// This function will be triggered by the defined timeInterval.
interval = setInterval(function () {
    // Get next char from string to be typed and concatenate to the display string.
    displayStr = displayStr + typeStr[typeIdx++];
    // Make a sandwich with the display string in between the original html pieces.
    $w("#typewriterPage").html = strPieces[0] + displayStr + strPieces[1];
    // Stop the interval from running when we get to the last character to by "typed".
    if (typeIdx === typeStr.length) clearInterval(interval);
}, timeInterval);
});
const$w=document.querySelector.bind(文档);
Object.defineProperty($w(“#typewriterPage”),“html”{
get:function(){返回this.innerHTML},
set:function(html){this.innerHTML=html}
});
//忽略以上所有评论
常量typewriterPage=$w(“#typewriterPage”);
const carouselWords=[“投资”、“金融”、“借款”、“贷款”];
typeWords(carouselWords,typewriterPage.html.split(“!”);
异步函数类型字(字、样式){
while(true){
words.unshift(words.pop());
常量[字]=字;
等待输入字(字、样式);
}
}
功能类型字(字、样式){
常量字符=[…单词];
让堆栈=“”;
返回新承诺(解决=>{
常量间隔=设置间隔(()=>{
如果(!字符长度){
解决();
间隔时间;
返回;
}
stack+=chars.shift();
typewriterPage.html=样式[0]+堆栈+样式[1];
}, 250);
});
}

!###
这在预览时适用于我的代码,但是当我发布网站时,只会看到“!###!”,我如何解决这个问题?在控制台中编写
$w(“#typewriterPage”).html
,点击
输入
,然后分享它所说的内容(不运行动画代码)。我不知道你的意思,我将它粘贴到控制台中的其余代码下。当我按下回车键时,它没有给我一个错误。我应该把它粘贴到其他地方吗?我的目的是找出
id
typewriterPage
的元素的默认HTML内容是什么。我相信是的!#!,这就是网站发布时所显示的内容,而这并没有被“触发”到单词数组中