Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Problema con variables

Estas en el tema de Problema con variables en el foro de Frameworks JS en Foros del Web. Buenas Estoy tratando de usar una funcion que encontre que cuenta de un numero a otra Funcion @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original < ...
  #1 (permalink)  
Antiguo 30/12/2010, 23:28
Avatar de Zuker  
Fecha de Ingreso: marzo-2007
Ubicación: Argentina
Mensajes: 164
Antigüedad: 17 años, 1 mes
Puntos: 1
Exclamación Problema con variables

Buenas

Estoy tratando de usar una funcion que encontre que cuenta de un numero a otra

Funcion

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. (function($) {
  3.     $.fn.countTo = function(options) {
  4.         // merge the default plugin settings with the custom options
  5.         options = $.extend({}, $.fn.countTo.defaults, options || {});
  6.  
  7.         // how many times to update the value, and how much to increment the value on each update
  8.         var loops = Math.ceil(options.speed / options.refreshInterval),
  9.             increment = (options.to - options.from) / loops;
  10.  
  11.         return $(this).each(function() {
  12.             var _this = this,
  13.                 loopCount = 0,
  14.                 value = options.from,
  15.                 interval = setInterval(updateTimer, options.refreshInterval);
  16.  
  17.             function updateTimer() {
  18.                 value += increment;
  19.                 loopCount++;
  20.                 $(_this).html(value.toFixed(options.decimals));
  21.  
  22.                 if (typeof(options.onUpdate) == 'function') {
  23.                     options.onUpdate.call(_this, value);
  24.                 }
  25.  
  26.                 if (loopCount >= loops) {
  27.                     clearInterval(interval);
  28.                     value = options.to;
  29.  
  30.                     if (typeof(options.onComplete) == 'function') {
  31.                         options.onComplete.call(_this, value);
  32.                     }
  33.                 }
  34.             }
  35.         });
  36.     };
  37.  
  38.     $.fn.countTo.defaults = {
  39.         from: 0,  // the number the element should start at
  40.         to: 100,  // the number the element should end at
  41.         speed: 1000,  // how long it should take to count between the target numbers
  42.         refreshInterval: 100,  // how often the element should be updated
  43.         decimals: 0,  // the number of decimal places to show
  44.         onUpdate: null,  // callback method for every time the element is updated,
  45.         onComplete: null,  // callback method for when the element finishes updating
  46.     };
  47. })(jQuery);
  48. </script>

El codigo para usarla (ademas de la funcion) es este

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.     jQuery(function($) {
  3.         var ini_counter0 = parseInt($('#totaldownloads').html());
  4.         var fin_counter0;
  5.  
  6.         $.get('data.php?i=0', function(data) {
  7.             fin_counter0 = data;
  8.         });
  9.  
  10.         $('#totaldownloads').countTo({
  11.             from: ini_counter0,
  12.             to: fin_counter0,
  13.             speed: 1000,
  14.             refreshInterval: 50,
  15.             onComplete: function(value) {
  16.             console.debug(this);
  17.             }
  18.         });
  19.     });
  20. </script>

El tema esta en que hay 2 variables que yo creo de donde obtengo el principio y el fin del contador.

A mi manera (se poco y nada de javascript) hice esto

var ini_counter0 = parseInt($('#totaldownloads').html());
var fin_counter0;

$.get('data.php?i=0', function(data) {
fin_counter0 = data;
});

El tema esta en que la funcion no me reconoce esas 2 variables a la hora de ejecutarlas... alguna idea de donde estoy equivocandome?

Gracias

Saludos!
  #2 (permalink)  
Antiguo 03/01/2011, 08:09
Avatar de chicohot20  
Fecha de Ingreso: mayo-2009
Mensajes: 388
Antigüedad: 15 años
Puntos: 43
Respuesta: Problema con variables

a ver prueba con esto:
Código HTML:
Ver original
  1. <script type="text/javascript">
  2.     jQuery(function($) {
  3.         var ini_counter0 = parseInt($('#totaldownloads').html());
  4.         var fin_counter0;
  5.  
  6.         $.get('data.php?i=0', function(data) {
  7.             fin_counter0 = data;
  8.             $('#totaldownloads').countTo({
  9.                 from: ini_counter0,
  10.                 to: fin_counter0,
  11.                 speed: 1000,
  12.                 refreshInterval: 50,
  13.                 onComplete: function(value) {
  14.                     console.debug(this);
  15.                 }
  16.             });
  17.         });
  18.  
  19.        
  20.     });
  #3 (permalink)  
Antiguo 15/01/2011, 17:17
Avatar de Zuker  
Fecha de Ingreso: marzo-2007
Ubicación: Argentina
Mensajes: 164
Antigüedad: 17 años, 1 mes
Puntos: 1
Respuesta: Problema con variables

Cita:
Iniciado por chicohot20 Ver Mensaje
a ver prueba con esto:
Código HTML:
Ver original
  1. <script type="text/javascript">
  2.     jQuery(function($) {
  3.         var ini_counter0 = parseInt($('#totaldownloads').html());
  4.         var fin_counter0;
  5.  
  6.         $.get('data.php?i=0', function(data) {
  7.             fin_counter0 = data;
  8.             $('#totaldownloads').countTo({
  9.                 from: ini_counter0,
  10.                 to: fin_counter0,
  11.                 speed: 1000,
  12.                 refreshInterval: 50,
  13.                 onComplete: function(value) {
  14.                     console.debug(this);
  15.                 }
  16.             });
  17.         });
  18.  
  19.        
  20.     });
Hola! Disculpa la demora, estuve de vacaciones!
Viendo desde el firebug en la pestaña consola obtengo

$(
[Interrumpir en este error] onComplete: function(value) {

Alguna idea? Gracias!

Etiquetas: variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:04.