Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Zmiana tła co sekundę
sher
post
Post #1





Grupa: Zarejestrowani
Postów: 51
Pomógł: 0
Dołączył: 9.07.2014

Ostrzeżenie: (0%)
-----


  1. function huh(){
  2. if (document.getElementById("hehehehe").style.background=="red") {
  3. document.getElementById("hehehehe").style.background="blue";
  4. }
  5. else {
  6. document.getElementById("hehehehe").style.background="red";
  7. }
  8.  
  9. setTimeout(huh, 1000);
  10. }
  11. huh();

Chcę, żeby tło zmieniało się co sekundę, z niebieskiego na czerwone i odwrotnie. Niestety, coś nie działa.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sher
post
Post #2





Grupa: Zarejestrowani
Postów: 51
Pomógł: 0
Dołączył: 9.07.2014

Ostrzeżenie: (0%)
-----


Dobra, ogarnąłem już temat samego gradientu w css (IMG:style_emoticons/default/tongue.gif)
  1. function huh(){
  2. var o=120-i;
  3. document.getElementById("hehehehe").style.background="background-image: linear-gradient(to top, rgba(255, 255, 255, 1) "+i+"px, rgba(255, 255, 255, 0) "+o+"px)";
  4. setTimeout(huh, 1000);
  5. i=i+x;
  6. }

W css'ie działało, natomiast w js nie jestem pewnien jak to napisać. Wszystkie te zmienne, itp. chyba są dobrze, jedynym problemem jest ta linijka z gradientem ;f
Go to the top of the page
+Quote Post
kafowi
post
Post #3





Grupa: Zarejestrowani
Postów: 75
Pomógł: 20
Dołączył: 13.02.2015

Ostrzeżenie: (0%)
-----


Cytat(sher @ 9.07.2015, 20:04:27 ) *
W css'ie działało, natomiast w js nie jestem pewnien jak to napisać. Wszystkie te zmienne, itp. chyba są dobrze, jedynym problemem jest ta linijka z gradientem ;f

Nie mogło działać (kod co podał nospor) bo najpierw musisz zdefiniować kolor, później wielkość.

  1. var i=0;
  2. var x=3;
  3. function huh(){
  4. document.getElementById("hehehehe").style.background="linear-gradient(to right, red "+i+"px, transparent)";
  5. i=i+x;
  6. setTimeout(huh, 1000);
  7. }
  8. huh();
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 12.10.2025 - 03:42