Category : setinterval

I have an accurate timer with the below class: class Timer { constructor () { this.isRunning = false; this.startTime = 0; this.overallTime = 0; } _getTimeElapsedSinceLastStart () { if (!this.startTime) { return 0; } return Date.now() – this.startTime; } start () { if (this.isRunning) { return console.error(‘Timer is already running’); } this.isRunning = true; this.startTime ..

Read more

I have the following html structure: <ul class="posts"> <li><img src="https://64.media.tumblr.com/1ff0b6435eaf4f2179e06cfbd9fca583/8fb2fa7b9e4b2d56-1f/s1280x1920/e1a986dea1f99a0cd9dcc7e672bb4a76254df4c4.jpg" class="hidden"></li> <li><img src="https://64.media.tumblr.com/70ec82e83c3c5835b10aec4927e253b8/8fb2fa7b9e4b2d56-d0/s540x810/c51483723f355f77a3ae6a17fe19da6525662b46.jpg" class="hidden"></li> <li><img src="https://64.media.tumblr.com/7d2f63f029ba23c1e4a6fe28fd6f52d7/8fb2fa7b9e4b2d56-80/s540x810/e6465ab8578c263f62075a2740b763822cbec270.jpg" class="hidden"></li> … </ul> Setting the items with css: .posts img { width: 100%; position: absolute; } .hidden { display: none; } .block { display: block; } This is my JS/jQuery: const blockClass = ‘block’; const hiddenClass = ‘hidden’; function ..

Read more

Looks like Chrome have a bug with CanvasRenderingContext2D and inactive tabs: when tab goes in inactive state, 2d context gets suspended and calls to drawImage or other methods doesn’t produce any effect. Code like that doesn’t work anymore when tab is in a background: const canvas = document.createElement(‘canvas’); const ctx = canvas.getContext(‘2d’); … setInterval(() => ..

Read more

I have a proprietary app that relies heavily on intervals and timeouts. When I try to debug problems happening before/after an interval, nothing works because the interval never triggers. Here’s a snippet of how I use intervals (assume all functions are implemented): useEffect(() => { let timerInterval; const stopTimer = () => { clearInterval(timerInterval); }; ..

Read more

Is it at all possible in jQuery to traverse the DOM (up/down/sideways) inside a setInterval using $(this) as a starting point? jQuery: var autoTimer = setInterval(function(){ // test code }, 1000) Test code tried: if($(this).length !== 0) { alert(‘hello’); } // alerts hello if($(‘body’).length !== 0) { alert(‘hello’); } // alerts hello if($(‘.className’).length !== 0) ..

Read more