Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Javascript prawidłowo wykonuje się w Chrome, nieprawidłowo w Firefox.
koxfx
post 7.10.2015, 19:58:44
Post #1





Grupa: Zarejestrowani
Postów: 47
Pomógł: 0
Dołączył: 18.04.2015

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


  1. <script>
  2.  
  3.  
  4. $(document).ready(function() {
  5.  
  6.  
  7. var refresh = setInterval(function(){
  8. var elem = document.getElementById('zna');
  9. elem = $("#zna").load("test.php");
  10.  
  11.  
  12. }, 3000);
  13.  
  14. });
  15. $("#zna").mouseup(function(){
  16. setInterval(refresh,1000);
  17. });
  18.  
  19. $("#zna").mousedown(function(){
  20. clearInterval(refresh);
  21. });
  22.  
  23.  
  24.  
  25. </script>


Podobny kod kiedyś działał prawidłowo we wszystkich przeglądarkach.
Obecnie Firefox bez drugiego setInterval prawidłowo czyści Timer. Jeśli drugie setinterval występuje to mousedown jest ignorowane.

Ten post edytował koxfx 7.10.2015, 19:59:13
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
trueblue
post 7.10.2015, 20:28:27
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Co to za kombinacja?
  1. var elem = document.getElementById('zna');
  2. elem = $("#zna").load("test.php");


Tu przekazujesz id licznika, nie funkcję.
  1. setInterval(refresh,1000);

Nawet nie, bo zmienna refresh jest poza zasięgiem tych dwóch funkcji.

Jaki efekt chcesz osiągnąć?

Ten post edytował trueblue 7.10.2015, 20:37:38


--------------------
Go to the top of the page
+Quote Post
koxfx
post 9.10.2015, 16:47:42
Post #3





Grupa: Zarejestrowani
Postów: 47
Pomógł: 0
Dołączył: 18.04.2015

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


  1. <script>
  2.  
  3.  
  4.  
  5. function odswiezaj()
  6. {
  7. $("#zna").load("test.php");
  8.  
  9.  
  10.  
  11. }
  12.  
  13.  
  14.  
  15.  
  16. $("#zna").mousedown(function(){
  17. clearInterval("odswiezaj()");
  18. });
  19.  
  20. $("#zna").mouseup(function(){
  21. setInterval("odswiezaj()",1000);
  22. });
  23.  
  24.  
  25.  
  26. </script>


Troche inny kod a objawy te same.

$("#zna").load("test.php"); ma się przestać wczytywać po wciśnięciu lewego przycisku myszy. Ma się ponownie wczytywać po jego zwolnieniu.

Ten post edytował koxfx 9.10.2015, 16:48:59
Go to the top of the page
+Quote Post
Comandeer
post 9.10.2015, 16:53:38
Post #4





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


clearInterval należy przekazać id timera, zwracany przez setInterval, nie funkcję.
Kod
var timer = setInterval(function() {}, 1000);
clearInterval(timer);


--------------------
Go to the top of the page
+Quote Post
koxfx
post 9.10.2015, 17:30:27
Post #5





Grupa: Zarejestrowani
Postów: 47
Pomógł: 0
Dołączył: 18.04.2015

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


Jak zrobie tak to jest to samo.
  1. $("#zna").mouseup(function(){
  2. var stop = setInterval("odswiezaj()",1000);
  3. });
  4.  
  5. $("#zna").mousedown(function(){
  6. clearInterval(stop);
  7. });
Go to the top of the page
+Quote Post
trueblue
post 9.10.2015, 18:02:33
Post #6





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Zmienna stop jest niewidoczna dla clearInterval, miałeś indentyczną sytuację w pierwszym kodzie.


--------------------
Go to the top of the page
+Quote Post
koxfx
post 9.10.2015, 18:28:42
Post #7





Grupa: Zarejestrowani
Postów: 47
Pomógł: 0
Dołączył: 18.04.2015

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


  1. $("#zna").mouseup(function(){
  2. var stop = setInterval("odswiezaj()",1000);
  3.  
  4.  
  5. $("#zna").mousedown(function(){
  6. clearInterval(stop);
  7. });
  8.  
  9. });
  10.  


Zrobiłem tak i działa. Dziękuję.
Go to the top of the page
+Quote Post
trueblue
post 9.10.2015, 18:31:23
Post #8





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


  1. var stop;
  2.  
  3. $("#zna").mouseup(function(){
  4. stop = setInterval("odswiezaj()",1000);
  5. });
  6.  
  7. $("#zna").mousedown(function(){
  8. if(stop) clearInterval(stop);
  9. });
  10.  
  11.  


--------------------
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: 14.08.2025 - 06:48