我想将更多图像添加到列表中,它会随机选择一定数量的图像。就像现在一样,所有图像都显示在列表中。知道我该怎么做吗?
这是 HTML 中的列表
<div id="sample">
<!-- start: Memory Lætt -->
<div class="kvilt-memory-game">
<ul>
<!-- back image (must be the first item) -->
<li><img title="Click to reveal" src="img/back.png" /></li>
<!-- match image (must be the second item) -->
<li><img title="Match made" src="img/matched.jpg" /></li>
<!-- image figures (add as many as you want) -->
<li><img id="ID01" title="Figure 01" src="img/ficard01.png" /></li>
<li><img id="ID02" title="Figure 02" src="img/ficard02.png" /></li>
<li><img id="ID03" title="Figure 03" src="img/fucard01.png" /></li>
<li><img id="ID04" title="Figure 04" src="img/fucard02.png" /></li>
</ul>
</div>
这是我执行的脚本
/* plugin methods */
var methods =
{
/* intialization */
init : function(options)
{
/* settings */
var settings =
{
spacing: 10, /* space between items */
columns: 4 /* number of columns */
};
return this.each(function()
{
var self = $(this), data = self.data('data');
if(!data)
{
/* overwrite default settings */
if (options && $.isPlainObject(options)) $.extend(settings, options);
/* get unordered list */
var list = self.find('ul').first();
/* get images data */
var datBack, datMatch, datFigs = [], numFigs, imgEl;
list.find('img').each(function(i)
{
imgEl = $(this);
if (i == 0) { datBack = { src: imgEl.attr('src'), title: imgEl.attr('title') }; }
else if (i == 1) { datMatch = { src: imgEl.attr('src'), title: imgEl.attr('title') }; }
else { datFigs.push({ src: imgEl.attr('src'), id: imgEl.attr('id'), title: imgEl.attr('title') }); }
});
datFigs = datFigs.concat(datFigs);
numFigs = datFigs.length;
/* init data */
self.data('data',
{
target: self,
list: list,
settings: settings,
datBack: datBack,
datMatch: datMatch,
datFigs: datFigs,
numFigs: numFigs,
itmData: null,
busy: false,
events: { init: $.Event('init'), match: $.Event('match'), done: $.Event('done'), reveal: $.Event('reveal'), fail: $.Event('fail') },
stats: { numClicks: 0, time: 0 },
matchCount: 0
});
/* generate items */
methods._generate.call(self, self.data('data'));
}
});