Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript] Odliczenie czasu
Forum PHP.pl > Forum > Przedszkole
bahh
Witam, chcę by funkcje które zostały napisane wykonywały się gdy wysokość okna przeglądarki była większa od 920 lub gdy mniejsza to podczas przewinięcia scrolla o 100 pikseli. Pierwszy warunek u mnie działa, drugi już nie. Będę wdzięczny jesli ktoś też zmniejszy ilość kodu do prostej postaci smile.gif

  1. $(document).ready(function(){
  2. $('#c1').text(0);
  3. $('#c2').text(0);
  4. $('#c3').text(0);
  5. $('#c4').text(0);
  6. var scrolledmax = (window.innerHeight||document.body.clientHeight);
  7. var scrolled = $(window).scrollTop();
  8. if (scrolledmax > 920)
  9. {
  10. jQuery({someValue: 0}).animate({someValue: 20}, {
  11. duration: 2000,
  12. easing:'swing',
  13. step: function() {
  14. $('#c1').text(Math.ceil(this.someValue));
  15. }
  16. });
  17.  
  18. jQuery({someValue: 0}).animate({someValue: 100}, {
  19. duration: 2000,
  20. easing:'swing',
  21. step: function() {
  22. $('#c2').text(Math.ceil(this.someValue));
  23. }
  24. });
  25.  
  26. jQuery({someValue: 0}).animate({someValue: 1000}, {
  27. duration: 2000,
  28. easing:'swing',
  29. step: function() {
  30. $('#c3').text(Math.ceil(this.someValue));
  31. }
  32. });
  33.  
  34. jQuery({someValue: 0}).animate({someValue: 2000}, {
  35. duration: 2000,
  36. easing:'swing',
  37. step: function() {
  38. $('#c4').text(Math.ceil(this.someValue));
  39. }
  40. });
  41. }
  42.  
  43. var scroll1 = 0;
  44. if (scroll1<scrolled)
  45. var scroll1 = scrolled;
  46.  
  47. if (scrolledmax <= 920 && scroll1>100)
  48. {
  49. jQuery({someValue: 0}).animate({someValue: 20}, {
  50. duration: 2000,
  51. easing:'swing',
  52. step: function() {
  53. $('#c1').text(Math.ceil(this.someValue));
  54. }
  55. });
  56.  
  57. jQuery({someValue: 0}).animate({someValue: 100}, {
  58. duration: 2000,
  59. easing:'swing',
  60. step: function() {
  61. $('#c2').text(Math.ceil(this.someValue));
  62. }
  63. });
  64.  
  65. jQuery({someValue: 0}).animate({someValue: 1000}, {
  66. duration: 2000,
  67. easing:'swing',
  68. step: function() {
  69. $('#c3').text(Math.ceil(this.someValue));
  70. }
  71. });
  72.  
  73. jQuery({someValue: 0}).animate({someValue: 2000}, {
  74. duration: 2000,
  75. easing:'swing',
  76. step: function() {
  77. $('#c4').text(Math.ceil(this.someValue));
  78. }
  79. });
  80. }
  81. });
zielu001
po co powtarzasz kod?
w scrolltop masz event
bahh
Bo nie wiem jak ten kod ułożyć, by działał w różnych warunkach - to gotowy kod znaleziony na internecie przerobiony pod moje potrzeby

Nie znam jQuery, zatem "scrolltop masz event" niewiele mi mówi smile.gif

up
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.