• Administrator
  •  
    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.

Moderators: asoo, Watchmens

Forum rules
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.
Post Reply
Omaradsl
Posts: 41
Joined: 02 Oct 2023, 21:07
Location: Italia
Has thanked: 16 times
Been thanked: 8 times
Contact:

change image automatically after a time javascript code

Post by 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:

Code: Select all

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

thanks bros.
User avatar
GIK-Team
root
Posts: 1027
Joined: 22 Mar 2018, 10:00
Location: Ukraine
Has thanked: 1161 times
Been thanked: 278 times
Contact:

Post by GIK-Team »

Omaradsl wrote: 13 Oct 2024, 19:19

Code: Select all

 
 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
User avatar
asoo
Posts: 2195
Joined: 03 Jan 2019, 01:48
Location: ͼͽ Thailand ͼͽ
Has thanked: 420 times
Been thanked: 2120 times

Post by asoo »

Omaradsl wrote: 13 Oct 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:

Code: Select all

 
 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
Posts: 41
Joined: 02 Oct 2023, 21:07
Location: Italia
Has thanked: 16 times
Been thanked: 8 times
Contact:

Post by Omaradsl »

asoo wrote: 14 Oct 2024, 00:06
Omaradsl wrote: 13 Oct 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:

Code: Select all

 
 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
Posts: 41
Joined: 02 Oct 2023, 21:07
Location: Italia
Has thanked: 16 times
Been thanked: 8 times
Contact:

Post by Omaradsl »

GIK-Team wrote: 13 Oct 2024, 21:27
Omaradsl wrote: 13 Oct 2024, 19:19

Code: Select all

 
 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.

Code: Select all

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!
Post Reply

Return to “Watchfaces discussion”

Who is online

Users browsing this forum: No registered users and 1 guest