Pagina 1 di 1

change image automatically after a time javascript code

Inviato: 13 ott 2024, 19:19
da Omaradsl
Hi guys, do you think there is a way to create a button like the one we use to change the background in our watchfaces, but which works so that it changes the background for example every 12 hours.
The method should be:
wallpaper 1 white from 8am to 7pm
wallpaper 2 dark from 7pm to 8am

from what little I remember about javascript you should declare the loop variable, like this:

Codice: Seleziona tutto

 
 this forum dont permit share my code
or could you add a function in the sasha editor that enables this function?

thanks bros.

Re: change image automatically after a time javascript code

Inviato: 13 ott 2024, 21:27
da GIK-Team
Omaradsl ha scritto: 13 ott 2024, 19:19

Codice: Seleziona tutto

 
 this forum dont permit share my code
Please try editing your post and inserting the code again. If the issue persists, let us know so we can assist further.

Re: change image automatically after a time javascript code

Inviato: 14 ott 2024, 00:06
da asoo
Omaradsl ha scritto: 13 ott 2024, 19:19
Hi guys, do you think there is a way to create a button like the one we use to change the background in our watchfaces, but which works so that it changes the background for example every 12 hours.
The method should be:
wallpaper 1 white from 8am to 7pm
wallpaper 2 dark from 7pm to 8am

from what little I remember about javascript you should declare the loop variable, like this:

Codice: Seleziona tutto

 
 this forum dont permit share my code
or could you add a function in the sasha editor that enables this function?

thanks bros.
You may use the sunrise sunset values ​​to determine the changes of the screen elements.

I have done this for GTR3 at the request of a member, but I am not sure if it will work for your needs.
You can see an example and more information at this link
viewtopic.php?p=15461#p15461

Re: change image automatically after a time javascript code

Inviato: 15 ott 2024, 09:09
da Omaradsl
asoo ha scritto: 14 ott 2024, 00:06
Omaradsl ha scritto: 13 ott 2024, 19:19
Hi guys, do you think there is a way to create a button like the one we use to change the background in our watchfaces, but which works so that it changes the background for example every 12 hours.
The method should be:
wallpaper 1 white from 8am to 7pm
wallpaper 2 dark from 7pm to 8am

from what little I remember about javascript you should declare the loop variable, like this:

Codice: Seleziona tutto

 
 this forum dont permit share my code
or could you add a function in the sasha editor that enables this function?

thanks bros.
You may use the sunrise sunset values ​​to determine the changes of the screen elements.

I have done this for GTR3 at the request of a member, but I am not sure if it will work for your needs.
You can see an example and more information at this link
viewtopic.php?p=15461#p15461
Thanks Asoo, Sorry I didn't reply right away but I've been very busy. I'll try to play around with the code you recommended. Thank you for your availability, you are all exceptional.

Re: change image automatically after a time javascript code

Inviato: 15 ott 2024, 09:13
da Omaradsl
GIK-Team ha scritto: 13 ott 2024, 21:27
Omaradsl ha scritto: 13 ott 2024, 19:19

Codice: Seleziona tutto

 
 this forum dont permit share my code
Please try editing your post and inserting the code again. If the issue persists, let us know so we can assist further.

Codice: Seleziona tutto

const images = [
    { img: 'https://picsum.photos/id/0/100', time: 3000 },
    { img: 'https://picsum.photos/id/1/100', time: 500 },
    { img: 'https://picsum.photos/id/10/100', time: 500 },
    { img: 'https://picsum.photos/id/100/100', time: 1000 }
];

const img = document.querySelector('img');
let index = 0;

function showNextImage() {
  const image = images[index++];

  if (!image) return;
  
  img.src = image.img;
  setTimeout(showNextImage, image.time);
};

showNextImage();
NOW WORK.
Thanks Boss!