JavaScript - script q no funciona

 
Vista:
Imágen de perfil de ivan dario

script q no funciona

Publicado por ivan dario (7 intervenciones) el 14/09/2017 12:39:55
Hola,
Mi problema es que he hecho un script de un contador hasta cierto numero el cual me funciona bien pero si coloco otro contador este no me funciona; solo me funciona si borro el anterior por que sucede esto??
os dejo el codigo gracias por la ayuda.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<body>
    <section>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
        <p>lihbfwlfbalifbelifyebhLFLIFBilhcb adbih adhgbaonqeuñfbefildhbvñidbrfuobrñisñ</p>
            <div class="title">
              <h2>Prueba></h2>
            </div>
            <article class="stats">
              <div>
                <h3>Prueba</h3>
                <p id="prueba1">0</p>
              </div>
            <div>
                <h3>prueba</h3>
                <p id="prueba2">0</p>
              </div>
            </article>
          </section>
 
          <script>
            window.onscroll = function () { myprueba1() };
 
            function myprueba1() {
              if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
                setInterval(myContador, 10);
              }
            }
 
            var y = 0;
            function myContador() {
              if (y == 2000) {
                clearInterval(myContador);
              } else {
 
                document.getElementById("prueba1").innerHTML = ++y;
              }
            }
          </script>
 
 
        <script>
             window.onscroll = function () { myprueba2() };
 
            function myprueba2() {
              if (document.body.scrollTop > 105 || document.documentElement.scrollTop > 105) {
                setInterval(myCount, 10);
              }
            }
 
            var x = 0;
            function myCount() {
              if (x == 2000) {
                clearInterval(myCount);
              } else {
 
                document.getElementById("prueba2").innerHTML = ++x;
              }
            }
      </script>
 
</body>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

script q no funciona

Publicado por xve (2100 intervenciones) el 14/09/2017 15:20:33
Hola Ivan, defines dos veces el mismo evento, por lo que unicamente se utiliza el ultimo definido.

Prueba a poner un solo evento onscroll() algo así:
1
window.onscroll = function () { myprueba1();myprueba2(); };
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de ivan dario

script q no funciona

Publicado por ivan dario (7 intervenciones) el 14/09/2017 16:42:57
ya lo he unificado todo en un script segun tu consejo muchas gracias ....
ya van dos cosas q aprendo gracias a ti te debo un cafe jajajaja
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar