Joshua's html

This commit is contained in:
chris committed 2012-11-29 00:59:46 +08:00
1 parent 390da0e49a
commit 06335f9bd1
26 files changed
+258 -1

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
// (function($) {
// var cache = [];
// // Arguments are image paths relative to the current page.
// $.preLoadImages = function() {
// var args_len = arguments.length;
// for (var i = args_len; i--;) {
// var cacheImage = document.createElement('img');
// cacheImage.src = arguments[i];
// cache.push(cacheImage);
// }
// }
// })(jQuery)
(function($) {
$.preloadimages = function (arr){
var newimages=[], loadedimages=0
var postaction=function(){}
var arr=(typeof arr!="object")? [arr] : arr
function imageloadpost(){
loadedimages++
if (loadedimages==arr.length){
postaction(newimages) //call postaction and pass in newimages array as parameter
}
}
for (var i=0; i<arr.length; i++){
newimages[i]=new Image()
newimages[i].src=arr[i]
newimages[i].onload=function(){
imageloadpost()
}
newimages[i].onerror=function(){
imageloadpost()
}
}
return { //return blank object with done() method
done:function(f){
postaction=f || postaction //remember user defined callback functions to be called when images load
}
}
}
})(jQuery)