用js改变backgroundImage属性,在iphone上测试,每次更换图片都会闪一下。
update:只有iphone会闪,使用了onload也闪,代码如下
function selection(num0, num1, num2) { var img = new Image(); img.src = urls[num0][1]; img.onload = function () { console.log("complete"); selections[num0].style.backgroundImage = "url(" + urls[num0][1] + ")"; list[num0].style.display = "block"; selections[num1].style.backgroundImage = "url(" + urls[num1][0] + ")"; list[num1].style.display = "none"; selections[num2].style.backgroundImage = "url(" + urls[num2][0] + ")"; list[num2].style.display = "none"; } }
数据分析师2017-10-01 00:45:17
js What should I do if the image flashes when I change the background-image? -PHP Chinese website Q&A-js What should I do if the image flashes when I change the background-image? -PHP Chinese website Q&A
Let’s take a look and learn.