只执行jQuery函数一次

只执行jQuery函数一次,jquery,function,fadein,preloader,temporary,Jquery,Function,Fadein,Preloader,Temporary,我想在页面加载时使用这个脚本来预加载和淡入一些图像 这对我很有效。我的问题是,如何更改它以只加载一次脚本 示例:用户访问“主页”(脚本预加载和fadein图像)->用户转到“关于页面”并返回“主页”(图像不应再次预加载/褪色,现在图像已缓存) 谢谢。将图像储存一定时间,然后从内存中加载图像,这样就不必每次都重新加载图像。一个特别不科学和丑陋的解决方案可能是从您的网站上检查推荐人的有效url。如果referer为null-运行小部件,否则不要运行小部件。我几乎讨厌我自己的建议,但它可能对你有用。我

我想在页面加载时使用这个脚本来预加载和淡入一些图像

这对我很有效。我的问题是,如何更改它以只加载一次脚本

示例:用户访问“主页”(脚本预加载和fadein图像)->用户转到“关于页面”并返回“主页”(图像不应再次预加载/褪色,现在图像已缓存)


谢谢。将图像储存一定时间,然后从内存中加载图像,这样就不必每次都重新加载图像。一个特别不科学和丑陋的解决方案可能是从您的网站上检查推荐人的有效url。如果referer为null-运行小部件,否则不要运行小部件。我几乎讨厌我自己的建议,但它可能对你有用。我能不能不使用
if/else
?预加载完成后,是否终止此脚本?
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
}