Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> useless setInterval call
marcini82
post
Post #1





Grupa: Zarejestrowani
Postów: 190
Pomógł: 1
Dołączył: 20.05.2005
Skąd: Poznań

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


Witam!

Usiluje napisac sobie obiekt sluzacy do przesuwania tekstu wewnatrz diva.
Oto zaczatki kodu:

  1. function Scroller(divId, direction) {
  2.  
  3. this.divId = divId;
  4. this.direction = direction;
  5. this.timeout = 0;
  6. this.interval = 0;
  7. this.startDelay = 0;
  8. this.stopDelay = 8000;
  9. this.stepDelay = 50;
  10.  
  11. this.startScrollNow = function(){
  12. var div = document.getElementById(this.divId);
  13. //div.scrollLeft = 0;
  14. this.interval = setInterval(this.nextStep, 25); // tu zglasza blad
  15. }
  16.  
  17. this.nextStep = function(){
  18. var staryScroll = div.scrollLeft;
  19. div.scrollLeft++;
  20.  
  21. }
  22.  
  23. }

Potem sobie to uruchamiam:
  1. var newsScroll = new Scroller("pasek_news", "left");
  2. newsScroll.startScrollNow();


Problem w tym, ze w linii gdzie jest setInterval() konsola js w Firefoksie wyrzuca blad:
Cytat
Błąd: useless setInterval call (missing quotes around argument?)


Jak zamiast this.nextStep dam nextStep, to pisze ze nie ma takiej funkcji...

Co jest zle?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
revyag
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

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


Zrób taki trik (IMG:http://forum.php.pl/style_emoticons/default/snitch.gif)

Kod
this.startScrollNow = function(){
    var div = document.getElementById(this.divId);
    var obj = this;
    //div.scrollLeft = 0;
    this.interval = setInterval(function(){ obj.nextStep() }, 25); // tu zglasza blad
}
Go to the top of the page
+Quote Post
marcini82
post
Post #3





Grupa: Zarejestrowani
Postów: 190
Pomógł: 1
Dołączył: 20.05.2005
Skąd: Poznań

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


Teraz wywala mi blad:
Cytat
obj.nextStep is not a function

I ten blad wypisuje kilkadziesiat razy na sekunde...

Ten post edytował marcini82 1.12.2006, 14:45:53
Go to the top of the page
+Quote Post
smentek
post
Post #4





Grupa: Zarejestrowani
Postów: 130
Pomógł: 11
Dołączył: 7.04.2003

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


obj jest obiektem a nie funkcją wiec nie możesz go wywołać jako funkcji.

Zamień obj.nextStep(); na obj.nextStep; i będzie działać.

  1. <?php
  2. this.startScrollNow = function(){
  3.    var div = document.getElementById(this.divId);
  4.    var obj = this;
  5.    //div.scrollLeft = 0;
  6.    this.interval = setInterval(function(){ obj.nextStep; }, 25); // tu zglasza blad
  7. }
  8. ?>
Go to the top of the page
+Quote Post
erix
post
Post #5





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




Jak już bez nawiasów, to tak:
Kod
this.interval = setInterval(obj.nextStep, 25); // tu zglasza blad

I musi działać; wywołuję tak różne zdarzenia od dawna i zawsze działa.
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: 24.08.2025 - 23:09