Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果display=";如何从数组中删除图像;无”;使用Vue.js?_Javascript_Vue.js - Fatal编程技术网

Javascript 如果display=";如何从数组中删除图像;无”;使用Vue.js?

Javascript 如果display=";如何从数组中删除图像;无”;使用Vue.js?,javascript,vue.js,Javascript,Vue.js,我正在我的项目中使用Vue.js。我有一个动画图像的背景,它们从上到下移动。连接到随机图像、位置等的所有内容都在已创建()内。: css 和html <div class="randImg"> <img class="image" :style="image.style" :src="image.src" v-for="image in addedImage"> </div> 我的网站是滞后的,因为图像正在无限

我正在我的项目中使用Vue.js。我有一个动画图像的背景,它们从上到下移动。连接到随机图像、位置等的所有内容都在
已创建()内。

css

和html

<div class="randImg">
    <img class="image" :style="image.style"
         :src="image.src"
         v-for="image in addedImage">
</div>

我的网站是滞后的,因为图像正在无限地添加到DOM中。我的动画的想法是,当我的图像100%处于关键帧上时,它将不显示任何内容。所以我决定简单地在
mounted()
内创建一个if语句,但它不起作用;我收到错误消息“ReferenceError:I未定义”


当图像显示变为无时,如何删除图像?

使用v-if删除样式为
display:none
的图像。我想你可以 删除
mounted()
中的所有代码


您希望每个图像持续五秒钟(基于动画持续时间),并且每250ms添加一个图像(基于changeInterval变量)。这意味着您的图像阵列最多需要包含20个图像,而不是当前限制为500个

您可以通过修改addImage函数来控制这一点,在添加最新图像之前删除最旧的图像。(你已经在这样做了,只是你要等到500个已经建立起来,然后马上剪掉300个;最好一次做一个:)


不需要从DOM中读取显示值,您只需根据时间来确保图像不会在应该删除之前被删除;修改数组是从DOM中删除元素所必需的全部。(为了以防万一,您可以在数组长度中多留一些,但不必一直到500。)
mounted()
在这种情况下不会有用,因为当组件第一次绘制到页面上时,该函数只运行一次,在addedImages数组中有任何内容之前。

我不确定您是否在使用jquery,但是如果您在使用jquery,那么您可以通过向图像添加一个类来使用,并删除那些不可见的图像?我没有使用它…我想您的
this.addedImages.splice(0,300)的方法是正确的--与其不断地向数组中添加图像,并尝试检测DOM中单个图像的显示以知道何时删除它们,不如将数组的长度限制在合理的范围内,并在添加新图像时删除最旧的图像。(等到有500个,然后一次砍掉300个,这可能太多了)你能解释得更深入一点吗?我试图理解,但仍然不:)当然,请看下面的答案。(我仍然有一个坏习惯,试图在评论中回答问题……)我想在显示为“无”时从数组中删除我的图像!我想要它,因为图像正在无限地添加到阵列中。我现在有另一个问题。。。我可以给你这个项目吗?如果你有一个不同的问题,你应该问自己的问题;如果它与上述内容相关,你能描述一下问题是什么,而不是仅仅链接到你的回购协议吗?比如说,它是连接的:)现在图像正在不连续地动画化!我不知道你说的是什么意思?你能说得更具体一点吗?这就是为什么我要发送存储库。。。这很难解释:D
.image {
  position: fixed;
  z-index: -1;
  opacity: 0;
  animation-name: animationDrop;
  animation-duration: 5s;
  animation-timing-function: linear;
  animation-iteration-count: 1;
  filter: blur(3px);
  will-change: transform;
}

@keyframes animationDrop {
  15% {
    opacity: 0.2;
  }

  50% {
    opacity: 0.4;
  }

  80% {
    opacity: 0.3;
  }

  100% {
    top: 100%;
    display: none;
  }
}
<div class="randImg">
    <img class="image" :style="image.style"
         :src="image.src"
         v-for="image in addedImage">
</div>
<div class="randImg">
  <template v-for="image in addedImage">
    <img v-if="image.style.display !== 'none'" class="image" 
       :style="image.style" :src="image.src">
  </template>
</div>
addImage() {
  if (this.addedImage.length > 20) {
    this.addedImage.shift() // remove oldest image (the first one in the array)
  }
  // add a new image to the end of the array:
  this.addedImage.push({
    style: {
      top: `${this.imgTop}px`,
      left: `${this.imgLeft}px`,
      height: `${this.imgHeight}px`,
      width: `${this.imgWidth}px`
    },
    src: this.selectedImage
  });
}