Ja, meine Prozentangabe war falsch aber sie ging wenigstens bis 100%. xD
Ich denke dein ++ ist nicht optimal gesetzt, bei der aktuellen variante wird die Rekursion einmal zu oft ausgeführt.
Geändert habe ich: das remove (hat nich geklapt), +1 verschoben, <= zu < und RLoad.LoadCount / RLoad.Scripts.length * 100
Meine Variante:
Code (JAVASCRIPT):
var RLoad = { } ;
RLoad.LoadCount = 0 ;
RLoad.Scripts = [
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js' ,
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js' ,
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js' ,
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js' ,
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js'
] ;
$( function ( ) {
//$.ajaxSetup({ cache: true });
RLoad.PreloadView = $( '<div style="position:absolute; top:7px; left:7px; border:1px solid black; background:white; padding:3px; font-size:10pt; font-family:\' courier\' " />' ) .appendTo ( $( 'body' ) ) ;
function autoloadScripts( url)
{
if ( RLoad.LoadCount < RLoad.Scripts .length )
{
$.ajax ( {
url: url,
dataType: 'script' ,
success: function ( ) {
RLoad.LoadCount += 1 ;
$( RLoad.PreloadView ) .html ( 'Loading: ' + Math.round ( RLoad.LoadCount / RLoad.Scripts.length * 100) + '% / 100 % ');
autoloadScripts(RLoad.Scripts[RLoad.LoadCount]);
},
error : function() {
$(' body').append(' File in ' + url + ' could not be loaded.');
}
});
}
else
{
$(RLoad.PreloadView).remove();
}
}
autoloadScripts(RLoad.Scripts[0]);
});