【发布时间】:2021-06-09 05:49:05
【问题描述】:
我正在尝试设置 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
})
});
【问题讨论】:
标签: javascript velo