我目前正在为网站创建徽标墙。我设法用地图随机显示它们,但现在我希望能够使它们一个接一个地随机显示(例如:图像1,图像6,图像3 ...),并且一旦它们出现就可以看到它们已经出现了。
我想我必须将其不透明度设置为0,然后将其不透明度设置为1,但是我看不到如何以随机方式进行此操作。
谢谢你的帮助。
编辑:
这是我的代码:
import React from "react"
const logoImages = [
{
image: "/assets/img/companies/altiplan.png",
src: "Michelin",
},
{
image: "/assets/img/companies/ametis.png",
src: "Michelin",
},
{
image: "/assets/img/companies/amplitrain.png",
src: "Michelin",
},
{
image: "/assets/img/companies/ar.png",
src: "Michelin",
},
{
image: "/assets/img/companies/artau.png",
src: "Michelin",
},
{
image: "/assets/img/companies/assaabloy.png",
src: "Michelin",
},
{
image: "/assets/img/companies/bag.png",
src: "Michelin",
},
{
image: "/assets/img/companies/bea.png",
src: "Michelin",
},
{
image: "/assets/img/companies/besix.png",
src: "Michelin",
},
{
image: "/assets/img/companies/bombardier.png",
src: "Michelin",
},
{
image: "/assets/img/companies/bouygues.png",
src: "Michelin",
},
{
image: "/assets/img/companies/ca.png",
src: "Michelin",
},
{
image: "/assets/img/companies/cartel.png",
src: "Michelin",
},
{
image: "/assets/img/companies/citymall.png",
src: "Michelin",
},
{
image: "/assets/img/companies/coyote.png",
src: "Michelin",
},
];
function shuffleMap(array) {
let currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array
/*array.sort(() => Math.random() - 0.5)
return array*/
}
const Image = ({image, src}) => {
return (
<div className='box'>
<div className='content'>
<img src={image} alt={src}/>
</div>
{/*language=CSS*/}
<style jsx>{`
.box {
min-width: 150px;
height: 200px;
overflow: hidden;
display: flex;
align-items: center;
background: #000;
}
img {
width: 120px;
filter: grayscale(1) invert(100%);
}
`}</style>
</div>
)
}
const allImages = shuffleMap(logoImages.map((companies, index) => {
return <Image key={companies.src+index} {...companies}/>
}));
const LogoWall = () => {
return (
<div className='container'>
{
allImages
}
{/*language=CSS*/}
<style>{`
.container {
width: 100vw;
height: auto;
display: flex;
justify-content: space-evenly;
align-content: space-around;
flex-flow: row wrap;
}
`}</style>
</div>
)
};
export default LogoWall
为什么在显示图像后不执行间隔
码: