首页 > 解决方案 > 尝试将数组中的任何图像插入到对象中

问题描述

我尝试以不同的速度向我的对象添加图像
构造函数

this.imagePaths = ['./assets/Bill-Gates.png', './assets/steve-jobs.png', './assets/zuckerberg.png'];
this.elementImg.src = `./assets/${() => { changeImage }};`;  

改变图像的功能

changeImage = () => {
    this.speed < 6 ? this.imagePaths[0] : (this.speed > 6 && this.speed < 9) ? this.imagePaths[1] : this.speed >= 9 ? this.imagePaths[2]
}  

现在我尝试使用三元运算符根据速度将图像添加到 elementtImgSrc。

标签: javascriptclass

解决方案


推荐阅读