我希望通过在页面加载时使用此脚本来预先渲染和淡化一些图像。
对我来说非常好。我的问题是,如何更改它以加载脚本一次。
示例:用户访问“主页”(脚本预加载和淡入淡出图像) - >用户进入“about-page”并返回“home”(图像不应再预加载/褪色,现在图像被缓存)
jQuery(document).ready(function() {
$('#bgstretcher').hide(); //hide all the images on the page
});
var i = 0; //initialize
var int=0; //Internet Explorer Fix
$(window).bind("load", function() { //The load event will only fire if the entire page or document is fully loaded
var int = setInterval("doThis(i)",500); //500 is the fade in speed in milliseconds
});
function doThis() {
var imgs = $('img').length; //count the number of images on the page
if (i >= imgs) { // Loop the images
clearInterval(int); //When it reaches the last image the loop ends
}
$('#bgstretcher:hidden').eq(0).fadeIn(1000);//fades in the hidden images one by one
i++;//add 1 to the count
}
由于