我正在尝试在我的网站上运行Type.js,我需要更改页面背景,具体取决于所输入的内容(“home”,“school”等)。我是网络开发的新手,我无法弄清楚为什么这不起作用。 Type.js可以正常工作,但后台没有任何反应。
这是我的代码:
$(function(){
$(".search").typed({
strings: ["home", "school", "work", "travel"],
typeSpeed: 0, // typing speed
loop: true, // loop on or off (true or false)
loopCount: false, // number of loops, false = infinite
onStringTyped: changeBGImage(self.arrayPos)
});
});
function changeBGImage(arrayPos) {
if (arrayPos == 0){
document.getElementById('page-background').className="bg-home";
} else if (arrayPos == 1){
document.getElementById('page-background').className="bg-school";
} else if (arrayPos == 2){
document.getElementById('page-background').className="bg-work";
} else if (arrayPos == 3){
document.getElementById('page-background').className="bg-travel";
}
}