Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery] Problem z metodą css
pehaperowiec
post 24.11.2011, 12:21:27
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 8
Dołączył: 26.09.2011

Ostrzeżenie: (10%)
X----


Kod
$().ready(function() {
    var path            ="img/";
    var imgArray        =["img.JPG",
                             "img2.JPG",
                          "img3.JPG"];
    var imgArrayLength    =imgArray.length;
    
    function slider() {
        for(var i=0;i<imgArrayLength;i++) {
            $("#slider").css({"background:":"url('"+path+imgArray[i]+"') 0 0 no-repeat"});        
        }    
    }
    
    setInterval(slider, 2000);
});
Gdzie popełniłem błąd ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
nospor
post 24.11.2011, 12:40:01
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




background:
po co tu dwukropek?
nie: css('styl:','wartosc');
a: css('styl','wartosc');

Z ajaxem problem nie ma żadnego związku. przenosze

ps: niby lecisz jakąś petlą, ale i tak za każdym razem w tej pętli nadpisujesz ten sam styl temu samemu elementowi. Po co więc ta pętla?

No i może łaskawie napisz jaki konkretnie masz problem.
Powód edycji: [nospor]:


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pehaperowiec
post 24.11.2011, 12:41:03
Post #3





Grupa: Zarejestrowani
Postów: 91
Pomógł: 8
Dołączył: 26.09.2011

Ostrzeżenie: (10%)
X----


Dziękuję bardzo za pomoc. Teraz już działa
Kod
$().ready(function() {
    var path            ="img/";
    var imgArray        =["img.JPG",
                             "img2.JPG",
                          "img3.JPG"];
    var imgArrayLength    =imgArray.length;
    var    i                =0;
    function slider() {
        if(i==imgArrayLength) {
            i=0;  
        }
        $("#slider").css({"background":"url('"+path+imgArray[i]+"') 0 0 no-repeat"});        
        i++;
    }
    
    setInterval(slider, 2000);
});
Go to the top of the page
+Quote Post
nospor
post 24.11.2011, 12:41:31
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




ps2:
o to:
Kod
var path            ="img/";
    var imgArray        =["img.JPG",
                             "img2.JPG",
                          "img3.JPG"];
    var imgArrayLength    =imgArray.length;
    
    function slider() {
        for(var i=0;i<imgArrayLength;i++) {
            $("#slider").css({"background:":"url('"+path+imgArray[i]+"') 0 0 no-repeat"});        
        }    
    }

Powinno być poza document. ready. To są deklaracje i one mają być widoczne wszędzie.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pehaperowiec
post 24.11.2011, 13:17:53
Post #5





Grupa: Zarejestrowani
Postów: 91
Pomógł: 8
Dołączył: 26.09.2011

Ostrzeżenie: (10%)
X----


możesz powiedzieć dlaczego tak powinno być ?
Go to the top of the page
+Quote Post
nospor
post 24.11.2011, 13:23:19
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




1) Ograniczasz deklaracje i funkcje tylko do danego bloku, co w tym przypadku raczej nie jest dobrym pomysłem
2) W ready z reguły podaje się kod jaki ma się wykonać po ready a nie deklaracje funkcji i zmiennych


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
pehaperowiec
post 24.11.2011, 13:24:33
Post #7





Grupa: Zarejestrowani
Postów: 91
Pomógł: 8
Dołączył: 26.09.2011

Ostrzeżenie: (10%)
X----


czyli tak[code]var path ="img/";
var imgArray =["img.JPG",
"img2.JPG",
"img3.JPG"];
var imgArrayLength =imgArray.length;
var i =0;

function slider() {
if(i==imgArrayLength) {
i=0;
}
$("#slider li").removeClass("active");
$("#slider li").eq(i).addClass("active");
$("#slider").css({"background":"url('"+path+imgArray[i]+"') 0 0 no-repeat"});
i++;
}

$().ready(function() {
setInterval(slider, 2000);
});[code]?
Go to the top of the page
+Quote Post
nospor
post 24.11.2011, 13:35:04
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Tak, i naucz się uzywac bbcode, a najlepiej lub PODGLAD przed wyslaniem posta


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.06.2025 - 21:10