这可能非常简单。防止在封面图像涂料之前显示底部图像
我有一个图像,然后绘制一个封面图像,灰色,并有一个“?”在它上面标记。基本上,顶部图像“隐藏”底部图像,直到用户可以“刮掉”封面图像。正在发生的事情是,在刷新后面的图像(如老虎机图像)“闪烁”,提供可能是一个获胜组合。
我有一个三乘三网格与9个可能的图像。
这里的网格是什么的例子: “?”
Sample Grid: http://www.omnimanager.co/images/sampleGrid.png
通知,灰盖与标记....以及当页面加载时,背景图像首先显示一秒钟,然后封面图像显示提供了一个可能的“提示”。
这里的加载代码:
的BOTTOM图像的加载代码:
var images = ['slide1.jpg', 'slide2.jpg', 'slide3.jpg',
'slide4.jpg', 'slide5.jpg', 'slide6.jpg',
'slide7.jpg', 'slide8.jpg', 'slide9.jpg'];
$(document).ready(function() {
//Scratch pad randomizer
for (var i = 1; i < 10; i++)
{
$('#wScratchPad3-' + i).css({'background-image': 'url(images/' + images[Math.floor(Math.random() * images.length)] + ')'});
}
});
下面的代码加载封面图像(S)的代码:
注:本代码位于document.ready函数的内部......为清晰起见,此处仅供参考。
//Scratch off monitoring
$("#wScratchPad3-1").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[0] = 100;
this.clear();
winner();
} else {
percentCmplt[0] = Math.round(percent);
}
},
backImage1: $("#wScratchPad3-1").css("background-image")
});
$("#wScratchPad3-2").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[1] = 100;
this.clear();
winner();
} else {
percentCmplt[1] = Math.round(percent);
}
},
backImage2: $("#wScratchPad3-2").css("background-image")
});
$("#wScratchPad3-3").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[2] = 100;
this.clear();
winner();
} else {
percentCmplt[2] = Math.round(percent);
}
},
backImage3: $("#wScratchPad3-3").css("background-image")
});
$("#wScratchPad3-4").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[3] = 100;
this.clear();
winner();
} else {
percentCmplt[3] = Math.round(percent);
}
},
backImage4: $("#wScratchPad3-4").css("background-image")
});
$("#wScratchPad3-5").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[4] = 100;
this.clear();
winner();
} else {
percentCmplt[4] = Math.round(percent);
}
},
backImage5: $("#wScratchPad3-5").css("background-image")
});
$("#wScratchPad3-6").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[5] = 100;
this.clear();
winner();
} else {
percentCmplt[5] = Math.round(percent);
}
},
backImage6: $("#wScratchPad3-6").css("background-image")
});
$("#wScratchPad3-7").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[6] = 100;
this.clear();
winner();
} else {
percentCmplt[6] = Math.round(percent);
}
},
backImage7: $("#wScratchPad3-7").css("background-image")
});
$("#wScratchPad3-8").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[7] = 100;
this.clear();
winner();
} else {
percentCmplt[7] = Math.round(percent);
}
},
backImage8: $("#wScratchPad3-8").css("background-image")
});
$("#wScratchPad3-9").wScratchPad({
cursor: 'cursors/coin.png',
scratchMove: function(e, percent)
{
if (percent >= 60)
{
percentCmplt[8] = 100;
this.clear();
winner();
} else {
percentCmplt[8] = Math.round(percent);
}
},
backImage9: $("#wScratchPad3-9").css("background-image")
});
总之,我想在后盖图像后做后图像绘制。
就是这样。
感谢
其他建议,不回答你的问题... –
遍历DOM成本,所以尝试缓存你的选择器,当你可以(保存一份$('#wScratchPad3-1')到一个变量,而不是调用两次) 。这使浏览器不必“多次”查找相同的元素。 –
此外,尽量保持您的代码干爽(不要重复自己)。很明显,你已经复制并粘贴了相同的代码块9次,每次都做一些小改动......不要那么做:) [code] $('。pads')。each(function( ({'background-image':'url(images /'+ images [Math.floor(Math.random()* images.length)] +')'}) 。wScratchPad({选项 - 我是循环的迭代器 }); }); [/ code] –