Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Preloader
kamilo818
post
Post #1





Grupa: Zarejestrowani
Postów: 250
Pomógł: 11
Dołączył: 20.01.2014

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


Witajcie.

Napisałem preloader obrazków na stronie:
  1. var images=$('img');
  2. console.log(images);
  3. var count=0;
  4. var step = 100/images.length;
  5. $('body').append('<div class="loader2"><img src="http://page4u.waw.pl/shop/712.gif"/><div class="loader_box"> </div></div>');
  6. images
  7. .load(function() {
  8. count++;
  9. console.log(count);
  10. $('.loader_box').html(Math.round(count*step)+"%<br>");
  11. if(count==images.length){
  12. $('.loader2').fadeOut();
  13. }
  14. })
  15. .error(function() { console.log("error loading image"); })
  16. .attr("src", $(this).attr("src"))
  17. ;
  18.  
  19.  
  20. $('div.wiecej').click(function(){
  21. var limit = parseInt($(this).attr('limit'))+20;
  22. window.location.hash =limit;
  23. });


Problem polega na tym że często się ten kot wykonuje tylko do 25% lub 49%. Mimo ze zmienna images zawiera wszystkie obrazki ze strony i na samej stronie widac ze wszystkie się wczytały.
Jak zaczne odswiezac stronę to w koncu przejdzie do 100%. Co tu jest nie tak?
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 21.08.2025 - 15:11