• Amministratore
  •  
    Support Ukraine
    If you experience any problems with the forum (it is not visible, there is no way to post messages, or some functionality does not work), please let us know. If you have problems with registration or you did not receive confirmation letter, let us know and we will activate your account manually.
    If you get an "The submitted form was invalid. Try submitting again" error, delete cookies, then try again.
     

change image automatically after a time javascript code

Topics related to the creation, development, and designing of the watch faces.

Moderatori: asoo, Watchmens

Regole del forum
When adding a new topic, use the template: Topic title [device name]
For example: How to create watch face [Falcon]
All communication in this branch should only be in English.
Rispondi
Omaradsl
Messaggi: 41
Iscritto il: 02 ott 2023, 21:07
Località: Italia
Has thanked: 16 times
Been thanked: 8 times
Contatta:

change image automatically after a time javascript code

Messaggio 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.
Avatar utente
GIK-Team
root
Messaggi: 1016
Iscritto il: 22 mar 2018, 10:00
Località: Ukraine
Has thanked: 1127 times
Been thanked: 267 times
Contatta:

Messaggio 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.
"sometimes it's scary but it's still just you and me” — Leaving Laurel
Avatar utente
asoo
Messaggi: 2130
Iscritto il: 03 gen 2019, 01:48
Località: ͼͽ Thailand ͼͽ
Has thanked: 411 times
Been thanked: 2050 times

Messaggio 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
ͼͽ To request please use the interrelated forum in action ͼͽ
Please do not PM to me for requests ported watchface.
Omaradsl
Messaggi: 41
Iscritto il: 02 ott 2023, 21:07
Località: Italia
Has thanked: 16 times
Been thanked: 8 times
Contatta:

Messaggio 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.
Omaradsl
Messaggi: 41
Iscritto il: 02 ott 2023, 21:07
Località: Italia
Has thanked: 16 times
Been thanked: 8 times
Contatta:

Messaggio 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!
Rispondi

Torna a “Watchfaces discussion”

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite