简体   繁体   English

window.setTimeout() 问题

[英]window.setTimeout() problems

I am new to vue js and i am trying to display two images at once onto my web page.我是 vue js 的新手,我试图在我的 web 页面上一次显示两个图像。 To illustrate, each image has its own settings such as imagePosition(left or right) and imagedisplayTime(display for 2 seconds).为了说明,每个图像都有自己的设置,例如 imagePosition(左或右)和 imagedisplayTime(显示 2 秒)。 So, let's consider this scenario, I have two images.所以,让我们考虑一下这种情况,我有两个图像。

image1: settings (display on the right side, 2 seconds) image1:设置(右侧显示,2秒)

image2: settings (display on the left side, 2 seconds) image2:设置(左侧显示,2秒)

In order to display these images onto the website i am using the following function:为了在网站上显示这些图像,我使用了以下 function:

callablelayout_assistant: function(new_layout, new_index, loop_time){
        if (new_layout === 1) {
        var position = this.loop_objects[new_index].position;
        if (position === 0) {
          this.left_timer = window.setTimeout(
            this.leftLoop.bind(undefined, new_index, new_layout), loop_time);
        } else if (position === 1) {
          this.right_timer = window.setTimeout(
            this.rightLoop.bind(undefined, new_index, new_layout), loop_time);
        }
      } else if (new_layout === 2) {

        var position = this.loop_objects[new_index].position;
        if (position === 0) {
          this.left_timer = window.setTimeout(
            this.leftLoop.bind(undefined, new_index, new_layout), loop_time);
        } else if (position === 1) {
          this.right_timer = window.setTimeout(
            this.rightLoop.bind(undefined, new_index, new_layout), loop_time);
        } else if (position == 2) {
          this.bottom_timer = window.setTimeout(
            this.bottomLoop.bind(undefined, new_index, new_layout), loop_time);
        }
      }
      else {
          clearTimeout(this.timer)
        this.timer = window.setTimeout(
          this.fullLoop.bind(undefined, new_index, new_layout), loop_time);
      }
    },

Here, i check the image's position whether it is “right side”, i call “rightLoop function”.在这里,我检查图像的 position 是否是“右侧”,我称之为“rightLoop 函数”。 or left side, i call leftLoop funciton.或左侧,我称之为 leftLoop 功能。 Also, I use "window.settimeout() to display the image on the screen but the problem is that i am only able to display one image at a time because “settimeout” will only display the next image according to the “loop time” of the previous image. What i want however, is that to display both image at the same time onto the web screen with regard to their own time. Any suggestion on how to do that? I'd appreciate any help!另外,我使用“window.settimeout() 在屏幕上显示图像,但问题是我一次只能显示一个图像,因为“settimeout”只会根据“循环时间”显示下一个图像上一张图片。然而,我想要的是在 web 屏幕上同时显示这两个图像关于他们自己的时间。关于如何做到这一点的任何建议?我会很感激任何帮助!

As you want to use vue.js, you need to look into vue components to accomplish what you need here.当你想使用 vue.js 时,你需要查看vue 组件来完成你所需要的。

Then, if you control the image rendering within a component, you can display two instances of your component, passing its loop time in props .然后,如果您控制组件内的图像渲染,则可以显示组件的两个实例,并在props中传递其循环时间。 Since each instance of the component can keep track of its loop time in its own data it will then be able to render itself according to that loop time.由于组件的每个实例都可以在其自己的data中跟踪其循环时间,因此它将能够根据该循环时间呈现自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM