Ver Mensaje Individual
  #12 (permalink)  
Antiguo 17/10/2013, 14:59
Ziddhartax
 
Fecha de Ingreso: octubre-2012
Mensajes: 27
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Problemas con async (jquery deja de funcionar)

Las pongo las dos dentro del mismo document.ready (el $.extend no se usa en más sitios)

Queda así

Cita:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"/> </script>
<script src="jquery.backgroundPosition.js" </script>

Y backgroundPosition.js

Cita:
$(document).ready(function(){

$.extend($.fx.step,{
backgroundPosition: function(fx) {
if (fx.state === 0 && typeof fx.end == 'string') {
var start = $.curCSS(fx.elem,'backgroundPosition');
start = toArray(start);
fx.start = [start[0],start[2]];
var end = toArray(fx.end);
fx.end = [end[0],end[2]];
fx.unit = [end[1],end[3]];
}
var nowPosX = [];
nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

function toArray(strg){
strg = strg.replace(/left|top/g,'0px');
strg = strg.replace(/right|bottom/g,'100%');
strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
}
}
});

});

$('#fondo1').css({backgroundPosition: '0px 0px'});
$('#fondo2').css({backgroundPosition: '0px 0px'});
$('#fondo3').css({backgroundPosition: '0px 0px'});

$('#fondo1').animate({
backgroundPosition:"(-50000px -5000px)"
}, 480000, 'linear');

$('#fondo2').animate({
backgroundPosition:"(-50000px -5000px)"
}, 240000, 'linear');

$('#fondo3').animate({
backgroundPosition:"(-50000px -5000px)"
}, 120000, 'linear');

});

En este caso los scripts no se ejecutan ni con async ni sin async

Pero me ha ocurrido una cosa muy curiosa, y te cuento.

Dejando esto en el html

Cita:
<script async src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"/> </script>
<script src="/jquery.backgroundPosition.js" ></script>


<script> $(document).ready(function(){

$('#fondo1').css({backgroundPosition: '0px 0px'});
$('#fondo2').css({backgroundPosition: '0px 0px'});
$('#fondo3').css({backgroundPosition: '0px 0px'});

$('#fondo1').animate({
backgroundPosition:"(-50000px -5000px)"
}, 480000, 'linear');

$('#fondo2').animate({
backgroundPosition:"(-50000px -5000px)"
}, 240000, 'linear');

$('#fondo3').animate({
backgroundPosition:"(-50000px -5000px)"
}, 120000, 'linear');

});
</script>
Y dejando esto en el background....js

Cita:
$(document).ready(function(){

$.extend($.fx.step,{
backgroundPosition: function(fx) {
if (fx.state === 0 && typeof fx.end == 'string') {
var start = $.curCSS(fx.elem,'backgroundPosition');
start = toArray(start);
fx.start = [start[0],start[2]];
var end = toArray(fx.end);
fx.end = [end[0],end[2]];
fx.unit = [end[1],end[3]];
}
var nowPosX = [];
nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

function toArray(strg){
strg = strg.replace(/left|top/g,'0px');
strg = strg.replace(/right|bottom/g,'100%');
strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
}
}
});

});
Entonces los scripts si se ejecutan, y fijate que estoy usando async

¡No entiendo nada!