使用setTimeOut时如何更改图像的不透明度?

时间:2019-05-25 12:24:19

标签: jquery

我试图在显示图片时更改图片的不透明度,但不确定如何在我的函数中使用它。

该代码运行正常,但是当我包含setAttribute时无济于事

for (j = 4; j > 0; j--) {

    if (keyPicture1 == reel01.length) {
        keyPicture1 = 0;
    }
    pictureInUse = reel01[keyPicture1];

    setTimeout((function(){
      this.el.src = this.pic;


      }).bind({el:document.getElementById("reel1-anima" + j).setAttribute("style","opacity:0.5", pic: 'images/image' + 
      pictureInUse + '.jpg', i: i, spinTimes: spinTimes, pictureInUse: pictureInUse, keyPicture1: keyPicture1}), duration);
      duration += interval;

      keyPicture1 += 1;
  }

1 个答案:

答案 0 :(得分:0)

将其更改为.prop()

.bind({el:document.getElementById("reel1-anima" + j).prop("style","opacity:0.5", pic: 'images/image' + 
      pictureInUse + '.jpg', i: i, spinTimes: spinTimes, pictureInUse: pictureInUse, keyPicture1: keyPicture1}), duration);
      duration += interval;