因此,我有以下超文本:
<ul id="nav">
<li><a href="somepage1.php" class="class1">Link1</a></li>
<li><a href="somepage2.php" class="class2">Link2</a></li>
</ul>
频率功能:
(function($) {
var imgList = [];
$.extend({
preload: function(imgArr, option) {
var setting = $.extend({
init: function(loaded, total) {},
loaded: function(img, loaded, total) {},
loaded_all: function(loaded, total) {}
}, option);
var total = imgArr.length;
var loaded = 0;
setting.init(0, total);
for(var i in imgArr) {
imgList.push($("<img />")
.attr("src", imgArr[i])
.load(function() {
loaded++;
setting.loaded(this, loaded, total);
if(loaded == total) {
setting.loaded_all(loaded, total);
}
})
);
}
}
});
})(jQuery);
备妥的触发点文件(简化):
$.preload([
path/to/image.jpg ,
path/to/image2.jpg ,
path/to/image3.jpg ,
path/to/image4.jpg ,
]);
It works really well, but I need to enhance it. When user click on anchor with class class1 , preloader should read images which are assigned to specific array. And I would need to write $.preload only once.
因此,我的想法是建立两个不同的阵列,如:
var arraysClass1 = [
path/to/image.jpg ,
path/to/image2.jpg ,
path/to/image3.jpg ,
path/to/image4.jpg
];
var arraysClass2 = [
path/to/image5.jpg ,
path/to/image6.jpg ,
path/to/image7.jpg ,
path/to/image8.jpg
];
之后,便制作文件,如灯塔。 <Im 困在此处,代码灯有误。
$( #nav a ).live("click", (function(event){
event.preventDefault();
var getClass = . +$(this).attr("class");
$(function() {
$.preload([
if(getClass== .class1 ){
arrayClass1;
}
elseif(getClass== .class2 ){
arrayClass2;
}
]);
});
I dont知道如何在美元封顶([...])内建立综合框架逻辑;