Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [jQuery] Problem z metodą css
pehaperowiec
post
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
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
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]:
Go to the top of the page
+Quote Post
pehaperowiec
post
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
Post #4





Grupa: Moderatorzy
Postów: 36 559
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.
Go to the top of the page
+Quote Post
pehaperowiec
post
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
Post #6





Grupa: Moderatorzy
Postów: 36 559
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
Go to the top of the page
+Quote Post
pehaperowiec
post
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
Post #8





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




Tak, i naucz się uzywac bbcode, a najlepiej lub PODGLAD przed wyslaniem posta
Go to the top of the page
+Quote Post

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: 3.10.2025 - 08:29