我正在尝试将wix条带的背景图像设置为在数组悬停时通过循环来更改图像。我没有看到编辑器中抛出任何错误,但是它仍然不能工作。这是我当前的代码。
$w.onReady(function () {
var image1 = "https://workful.com/blog/wp-content/uploads/2019/10/Women-in-Small-Business.jpg";
var image2 = "https://data.europa.eu/sites/default/files/news/2020-25-3.jpg";
var image3 = "https://thumbor.forbes.com/thumbor/960x0/https%3A%2F%2Fblogs-images.forbes.com%2Fstartswithabang%2Ffiles%2F2017%2F10%2FTiny_bit_of_U.jpg";
var Background_imagez = [image1,image2,image3];
let playing = false;
let current = 0;
const run = () => {
setTimeout(() => {
$w('#columnStrip1').background.src = Background_imagez[current];
if (current < Background_imagez.length) {
current++;
} else { repeat() }
}, 500);
}
const repeat = () => {
current = 0;
run();
}
$w('#text59').onMouseIn(() => {
playing = true;
while (playing) { run() }
})
$w('#columnStrip1').onMouseOut(() => {
playing = false;
current = 0;
$w('#columnStrip1').background.src =
'https://wallpapercave.com/wp/wp2831956.png' ||
'https://images.unsplash.com/flagged/photo-1593005510329-8a4035a7238f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8&w=1000&q=80'; // Default
})
});发布于 2021-06-09 17:26:55
您错误地使用了for循环。
for循环不返回值,因此不能将它们赋给变量。您还错过了在分配let index = 0之前添加for
for (let index = 0; index < Background_imagez.length; index++) {
$w('#columnStrip1').background.src = Background_imagez[index];
}我不确定上面的图片是否真的会显示除最后一张图片之外的任何东西,因为它可能会循环太快,任何人都看不到,但它应该可以修复您的Identifier expected错误。
请参阅MDN上的for loops文档
https://stackoverflow.com/questions/67898299
复制相似问题