仅在首次访问网站时运行JS加载程序

时间:2013-12-29 02:20:02

标签: javascript jquery preloader

我在我的网页上使用了一个非常简单的加载Javascript,其中包含:

$(window).load(function() { $("#spinner").fadeOut("250"); })

然后在我的CSS中

#spinner {
display: none;
position: fixed;
text-align: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 100001;
background: white;
}

#spinner:after {
position: fixed;
content: "Loading, it will take a few seconds, please wait";
color: black;
top: 50%;
margin-left: -242px;
}

现在我想让它在第一次访问该页面时加载,而不是每次都加载(看起来非常烦人)。

任何帮助都将非常感激。 费德里科

1 个答案:

答案 0 :(得分:0)

要执行您想要的操作,您必须使用Cookie,localstorage或某些数据库等在页面加载之间存储信息。

正如我在上面的评论中所提到的,如果您觉得首先需要附加到页面加载的微调器,您可以考虑重新考虑原始设计/处理性能。