4,759 questions
-4
votes
3
answers
50
views
Set Interval Js [duplicate]
I want to make a slide show with JS using the setInterval function, but I don't know why my code is not working? While there is no error in console, I have a number of pictures that start with the ...
2
votes
3
answers
41
views
How to use useState, Dispatch input?
Consider this code:
const [seconds, setSeconds] = useState<number>(START_VALUE);
useEffect(() => {
const intervalId = setInterval(() => {
setSeconds((previousSeconds) => ...
0
votes
0
answers
53
views
Why is my setInterval for a carousel not working?
I've been trying to make my carousel work with arrows manually and for it to automatically slide as well but the automatic slide part isn't working. The arrows work fine im not sure if they're the ...
0
votes
1
answer
49
views
Delayed function execution of setInterval
I'm trying to delay the execution of the setInterval function, which is set at 2000.
Ideally, I would like the function to be executed after 10000 at every refresh of the page + after each hide on ...
0
votes
1
answer
31
views
How to fix timer inside useEffect freezes on frequent rerenders?
In my react app I have highly interactive component where there are a lot of frequent re-renders that are happening on user keyboard inputs. I also want to represent timer in this component. I have a ...
0
votes
1
answer
25
views
Get SVGator Javascript API to work in a timer loop
I have a 4 second SVGator animation that needs to run in it's entirety, then have the last 2 seconds loop indefinitely. I've exported as SVG/Javascript, then used the following JS code...
const ...
-2
votes
1
answer
116
views
Is there a function or way to stop the setinterval function from keep on running after a match in jQuery or JS?
The project that I'm working on, generates 2 different p elements and each one is triggered independently. It takes about 5 seconds to load after the callback. I have no control over any of these p ...
2
votes
1
answer
65
views
Javascript loop to wait for input from external source (Android tasker)
I am having a hard time with wait loops in JavaScript to wait for content from an external source (tasker).
In particular I have an HTML document with JavaScript (shown in a WebView element inside a ...
0
votes
2
answers
125
views
Why does setInterval in my typewriter effect skip the second character (index 1) and display remaining characters correctly?
I am implementing a typewriter effect in my React app where I fetch a string from a URL and display it one character at a time. I expect the effect to start from the first character (index 0) and ...
3
votes
2
answers
56
views
Behaviour of setInterval with respect to Event loop
Trying to figure out why the output of the following code is the way it is
console.log("Start");
setInterval(function() {
console.log("setInterval");
}, 5000);
let date = new Date();
while(...
0
votes
1
answer
32
views
Updating Dynamic changes to fetching Data
I am stuck at the moment. I created the funcitonanilty to control how often data is is fetched using calculation of milliseconds to seconds,munutes and hours, which seems to be working fine.
The issue ...
0
votes
0
answers
40
views
Drawing canvas shapes dynamically with setInterval in React
I'm making a simple game with HTML Canvas and React. The idea is that we have 2 heroes (big circules), which are moving on opposite sides of the field and throwing spells (small circules) to each ...
2
votes
1
answer
43
views
How do I change the background colour of a class at midnight everyday rather than by a user event
Currently I have a piece of code that changes the background colour of a class every 24 hours. However if a user refreshes the page, the 24 hour cycle starts from the beginning – so they would only ...
1
vote
2
answers
98
views
minIndex always = i even after changing its value multiple times?
i'm new to javascript and programming (3 months) and am trying to make a sorting algorithm visualizer like the ones you see on youtube. i had an issue where the for loops usually used were just way to ...
0
votes
0
answers
23
views
Unexpected behavior of setTimeout/setInterval when tab is inactive [duplicate]
I've implemented a user activity tracking and countdown timer in React using setTimeout and setInterval. Everything works fine when the browser tab is active, but I'm facing issues when the tab is ...
0
votes
1
answer
54
views
Using setInterval in javascript [duplicate]
I modified a javascript code using setInterval to alternate between two messages using innerHTML. I tried document.write and it works. But innerHTML does not work.
// Create global interval and ...
0
votes
0
answers
23
views
react native Stopwatch : restart immediatly after a stop
I have a stopwatch running. I need to stop and restart from 0 immediatly when the user click a button. It's working if the user click Stop and then click a Start button. But when I try to do that in ...
0
votes
0
answers
30
views
How to handle clearInterval() from a different function in typescript [duplicate]
I am experiencing a problem on how I will stop the time interval on my code.
How can I clear interval in typescript?
I used interval to generate all the excel tabs separately. Generating excel file is ...
-2
votes
2
answers
41
views
The state is not updating correctly inside setInterval of useEffect in react
I'm facing issue in updating the setStartTime inside setInterval function.
I want to update the startTime every minute. To update that, I've created a useRef and storing the value in timeRef.current. ...
1
vote
1
answer
79
views
automatically loop through radio buttons but also be able to manually switch
I'm trying to iterate through radio buttons automatically every 5 seconds via jquery; however i need the function to also run when i manually switch buttons. Here's what I have so far:
$(document)....
0
votes
0
answers
77
views
ReactJS and Router DOM - Memory leak and persisting setInterval of an async function in a useEffect
I'm trying to set up a setInterval in a useEffect for an async function that fetches from a URI. I'm using React Router DOM to set up a few pages for the app. The problem I'm facing is that a memory ...
2
votes
1
answer
51
views
useInterval JS useState React and Animation CSS
I am changing text between two values using React useState and setInterval and it works fine.
function Home() {
const [role, setRole] = useState("Text A");
const inter = setInterval(() =...
0
votes
3
answers
158
views
How does one enforce a chron-job to be executed exactly at every possible 5 minute mark (0:00, 0:05, 0:10) regardless of the chron-job's start time?
I have a JavaScript function of chrome extension that I need to run at exact 5-minute intervals, synchronized with the current time. For example, it should run at 5:00, 5:05, 5:10, and so on, ...
-2
votes
2
answers
44
views
my javascript stopwatch project isn't working properly
I coded a stopwatch watching tutorials with JS. I commented out a few lines of code that my tutor had written, something that I do not understand. So after I commented those lines out, whenever I ...
1
vote
0
answers
117
views
How to reactively display websocket.readyState in vue3?
I want to display websocket.readyState in component reactively. But it doesn't change the display status in a timely manner. It always change display at next time.
The code can't work properly:
let ws ...
0
votes
0
answers
46
views
setInterval method getting wrong lastChild and i don't know why?
const randomDelay = ()=>{
return new Promise((resolve,reject)=>{
const timeout = (Math.random()*10)%7;
setTimeout(() => {
resolve();
}, timeout*1000);
...
0
votes
0
answers
49
views
difference in setInterval() speed on different browsers [duplicate]
let scramble = document.getElementById('scramble');
let timer = document.getElementById('timer');
const possibleMoves = ["R", "R'", "R2", "L", "L'", &...
0
votes
2
answers
232
views
Displaying the time in react using use effect
import React, { useState, useEffect } from 'react';
function Child() {
const [time, setTime] = useState(new Date());
useEffect(() => {
const interval = setInterval(() => {
setTime(...
0
votes
0
answers
61
views
Problem with useEffect() in React project
I've got this React app which sends a 'Post' request. The problem is that: i'm using useEffect(() to automate the sending process
of my messages and the application is not capturing the "...
0
votes
0
answers
39
views
How to use the async function axios into setInteval or setTimeOut?
I tried to send data regularly from react to laravel by using axios into setInterval, but it send an empty array.
Here is my code:
const consultationTable = useSelector(
(state) => state....
0
votes
0
answers
33
views
I made a JavaScript daily trigger for a function that updates an innerHTML and it didn't run properly
function triggerDailyUpdate() {
console.log('the Function worked');
setInterval(function(){
const now = new Date();
if (now.getHours() === 0 && now....
0
votes
2
answers
64
views
changing the width of a div with setinterval
I have this code with css animation:
@keyframes progress-bar {
0% {
width: 0;
}
50% {
width: 100%;
}
100% {
width: 0;
}
}
.box {
position: relative;
height: 3px;
...
0
votes
3
answers
142
views
How to execute a setInterval function every time a key is pressed and stop when a key is not pressed in JS?
I need to execute a setInterval function only when a specific key (F in this case) is being pressed, and then clear it when the key is not pressed.
So far, I have tried this:
var process;
function ...
0
votes
2
answers
54
views
Run clearInterval with IntersectionObserver
I have a short code that runs a setInterval only when the element is in view, but for some reason it won't cancel when the element gets out of view. I don't know if I misunderstood InteractionObserver ...
-2
votes
1
answer
37
views
JavaScript SetInterval toggle between Heads and Tails
I am writing a simple coin toss script. I want to animate between Heads and Tails for 1 second before the result is output. I am using a SetInterval. I want the display to change between Heads and ...
0
votes
1
answer
53
views
Generate text in HTML canvas from the center printing one character at a time, with string dynamically adjusting to the formatting
I'm building a website that draws a string into a canvas one character at a time, I've managed to code this first part, but what I'm now trying to do is making the text generate on the center and ...
0
votes
0
answers
106
views
Play CSS animation on idle / user inactivity on webpage
I want to play CSS animation on multiple elements with a single CSS class when the webpage is idle or the user is inactive for 3 seconds. I have tried javascript function. It works fine for 1st ...
1
vote
1
answer
87
views
Main thread frozen handling interval, sending accumulated data with enormous delay [closed]
I have written an application in Tauri, Rust + JS React. When the machine connected to the app stops working, the app sends to database equivalent of the injection but in other state like machine ...
1
vote
3
answers
77
views
IF Else statement not properly worked in setInterval() function while creating count-down timer
Even after adding if else statment inside setInterval() function to clear the interval once my time variable reaches 0, the setInterval() is still running with negative time value.
Please specify what ...
0
votes
0
answers
13
views
How to detect a pressed button using setInterval and without any event in javascript?
I want to get a pressed mouse or keyboard button from global object window or document when it's listening in setInterval.
setInterval(function () {
window.mouse.button. ...;
window.keyboard....
0
votes
0
answers
30
views
react the function of key and useEffect
import { useState, useCallback, useRef } from 'react';
import QUESTIONS from '../questions.js';
import QuestionTimer from './QuestionTimer.jsx';
import quizCompleteImg from '../assets/quiz-complete....
0
votes
0
answers
53
views
How to build a responsive timer for a multiplayer game
I'm building a multiplayer trivia game with React and I've been struggling with building a timer component. The goal would be to implement a time limit per round.
This is the logic behind the feature: ...
-1
votes
1
answer
590
views
Angular 17 does not update view using setInterval with NG0500 error in console
I am building a countdown timer component and trying to display updated 'seconds' value within every second, but I do not see any update on UI
When I do not use outside zone attitude, then page is ...
0
votes
2
answers
67
views
clearInterval() doesn't stop setInterval() method
I would like to stop setInterval using clearInterval(). But intervalId is undefined. I don't know why.
import { useState } from 'react';
function Component() {
const [counter, setCounter] = ...
0
votes
0
answers
48
views
NodeJS: WorkerThread or setInterval?
I currently writing a Node app that will launch a bunch of services to check a condition every X seconds and if the result is true, will perform some actions.
My first implementation is to instantiate ...
0
votes
1
answer
48
views
setnterval is acting unpredictably in React Project causing multiple changes to State Array
In the above component of my React project I have used setInterval to create a State Array that has a maximum size of 10 and used ChartJS to represent the changes in that Array in a Line Graph, but ...
0
votes
0
answers
83
views
Enabling setInterval or react-idle-timer to Run in Computer Sleep Mode
I'm currently working on a project where I need to execute periodic tasks in a React application, ideally every 28 minutes. However, I've encountered an obstacle with setInterval as it seems to pause ...
2
votes
2
answers
479
views
Interval function causes infinite UI load unless I type in "/index.html" in the URL
I'm trying to make a simple digital clock in my Angular app, but currently I'm just having it display a counter while I figure out what the heck is going on:
In clock.component.html:
<div class=&...
4
votes
3
answers
2k
views
The SetInterval function does'nt work in Angular 17
When i use setInterval in Angular the browser doesnt load the content anymore. This problem just happens in Angular 17. I dont know if im the only one with this or if nobody in Google or in Angular ...
-2
votes
2
answers
102
views
How can I make the instances of my SuperCounter class stop counting independently?
I just created a counter class that seems to work almost okay.
Unfortunately there is an issue that I cannot identify.
I instance my class twice with a different name but the parameters remain the ...