Issues with window.setTimeout()

As a beginner in vue js, I am faced with the challenge of displaying two images simultaneously on my website. Each image has unique settings such as imagePosition (left or right) and imagedisplayTime (display for 2 seconds). Let's consider this scenario where I have two images:

Image1: settings (display on the right side, 2 seconds)

Image2: settings (display on the left side, 2 seconds)

To implement the display of these images on the website, I am using the following 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);
      }
    },

In this function, I determine the image’s position to call the appropriate function such as "rightLoop" for the right side and "leftLoop" for the left side. However, the issue I face is that only one image is displayed at a time due to the nature of "setTimeout" function which displays the next image based on the previous one's loop time.

My goal is to find a way to display both images simultaneously on the web screen while respecting their individual display times. Any suggestions or guidance would be greatly appreciated!

Answer №1

If you are considering using vue.js, exploring vue components is essential for achieving your goals here.

You can manage image rendering within a component by displaying two instances of the component and passing its loop time in props. By allowing each instance to keep track of its loop time in its own data, it will then autonomously render based on that specific loop time.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Include a new button in the react material-table toolbar

I am looking to enhance the material-table toolbar by adding a new button. This button will not be directly related to the table, but instead, it will open a modal window with additional information. The button I want to add is called "quotations" and I w ...

Troubleshooting: Unable to trigger click event on Vuejs component

Working with Vuejs and Vuikit components, I have set up the following structure: <template> <div class="uk-scope"> <vk-modal :show="isShow" v-if="config"> <vk-modal-close @click="alert('hello!')" large& ...

JavaScript will not be passed down to loaded content

Let's say I have two files: main.php additional-content.php In the main.php file, that's where I include my CSS and JS: <head><link href="css/style.css" rel="stylesheet" type="text/css" /></head> <body><script src=" ...

Error being thrown in Express/Mongoose not being caught and handled

While using Postman to test my APIs, I'm encountering an issue with mongoose. It seems that when I use throw new Error() within the userSchema, the error does not get caught by the route.post. How can I ensure that errors thrown using throw new Er ...

Use jQuery to create rows within each div

Can someone assist me with the following issue? I have created an HTML grid where objects are displayed on the left side, and a row is shown for each object on the right side. I am looking to use jQuery to add 8 items in a row on the right side for each o ...

Increase division height when mouse hovers over it

I want the height of the div to be 50px by default and change to 300px onmouseover. I have implemented this as follows: <style type="text/css"> #div1{ height:50px; overflow:hidden; } #div1:hover{ height:300px; } </style> <body> <div i ...

What causes my TypeScript to occasionally return an instance and other times return a class?

I've been developing an app to enhance my understanding of TypeScript. It functions perfectly in Chrome, however, I encounter a problem when running it in Edge. The issue lies within this method: set position(pos: Point) { const diffAsPoint ...

Organize angularjs ngRepeat with updated data outcomes

I am facing a situation where I need to display results from different ajax sources, but they are loaded asynchronously. The problem is that I want the results to be sorted alphabetically once they are all loaded. ngRepeat doesn't sort them correctly ...

Guidance on invoking the navigate function from a component displayed at the highest level of rendering

Within the react-navigation documentation, it is explained that you can initiate navigation from the top-level component using the following method: import { NavigationActions } from 'react-navigation'; const AppNavigator = StackNavigator(SomeA ...

Error alert: TypeScript typings issue - Naming conflict with Promise / Failure to locate name Promise

I am currently working on a client/server JavaScript application and I am facing a significant issue with Promises. It appears that they are either undefined or duplicated, and this problem seems to be related to the @types package. npm install --save @ty ...

What is the best method for breaking down oversized controllers into several files within Express?

I’ve been working on an express application and so far, I’ve only had one controller file called users. This file includes different functions related to users like signUp, signIn, and getPersonalInfo. These functions are exported using module.exports ...

"Utilizing Ajax to dynamically update the content within a

Just getting started with JavaScript and ajax, so please bear with me. I'm attempting to use an ajax function to update content in a div when a link is clicked. However, I keep running into the error: "ajaxpage is not defined". The ajaxpage functio ...

Tips on passing a variable and API response to the following promise in JavaScript!

Using the initial promise "crypto.model.find()" allows me to store an array of "symbols" ( symbol[] ) from the database and retrieve some IDs that I will utilize to construct a URL for making a request to an API using axios.get(url). Upon receiving a resp ...

Struggling with Vue 2's v-model not properly binding data and potentially removing properties?

I am currently dealing with a situation where I have a select element bound to nested data: <select class="form-control" v-model="user_profile.sport.sport_id"> <option v-for="sport in sport_information.sports" :value="sport.sport_id"> ...

Is it feasible to alter cookie data within a jQuery ajax call?

I'm currently developing a Chrome extension that enables users to capture all HTTP requests for a specific website, edit components of the request, and then send it again. My plan is to utilize jQuery's ajax function to design and dispatch the a ...

How to access scss variable from the <template> section of a VueJS component

Within my VueJS project, I maintain a file named variables.scss that houses specific variables which I typically import using @import within the <style/> section of my components when needed locally. While this method functions as expected, I am curr ...

Challenges with Network Speed Impacting Mongoose Database Write Operations

I've implemented the below code snippet to update a user account within my application: "use strict"; var mongoose = require("mongoose"); mongoose.set("debug", true); mongoose.connect(process.env.MONGO_URL, { auth: ...

"Experience the power of Angular.js through seamless animations created by blending the capabilities

I want to smoothly fade out the old view and fade in the new view. The challenge is that the new content must be positioned absolutely until the old one fades out. I also want to set a specific top position and height for the new content, but when I try to ...

Getting a specific nested child component from the parent component's slot in the render function: A step-by-step guide

I have successfully implemented conditional rendering of a child component using the render function. Below is an example of the parent component with the child component: <Parent :index="1"> <Child> ... </Child> <Child&g ...

Pause animation when hovering over their current positions

I am working on a project with two separate divs, each containing a circle and a smiley face. The innercircle1 div is currently rotating with a predefined animation. My goal is to create an effect where hovering over the innercircle1 div will pause its rot ...