Page 1 of 1
change image automatically after a time javascript code
Posted: 13 Oct 2024, 19:19
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.
Re: change image automatically after a time javascript code
Posted: 13 Oct 2024, 21:27
by GIK-Team
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
Posted: 14 Oct 2024, 00:06
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
Re: change image automatically after a time javascript code
Posted: 15 Oct 2024, 09:09
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.
Re: change image automatically after a time javascript code
Posted: 15 Oct 2024, 09:13
by Omaradsl
GIK-Team wrote: 13 Oct 2024, 21:27
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!