我试图弄清楚如何让某个 div 每次有人访问我的网站时显示一次。我已经看到了两种使用 javascript 和 php 的方法,但没有成功。
这是我的代码,我希望(如果可能的话)#spinner div(以及其中的所有内容)在每个会话中显示一次。
<body>
****This part would only be displayed once****
<div id="spinner" style="display: none;">
<div class="sketch">
<canvas id="canvas" width="1280" height="224"></canvas>
<script>var canvas = document.getElementById('canvas')
, context = canvas.getContext('2d')
, img = new Image()
, w
, h
, offset
, glitchInterval;
img.src = 'http://www.bccustommade.com/images/loading.png';
img.onload = function() {
init();
window.onresize = init;
};
var init = function() {
clearInterval(glitchInterval);
canvas.width = w = window.innerWidth;
offset = w * .1;
canvas.height = h = ~~(175 * ((w - (offset * 2)) / img.width));
glitchInterval = setInterval(function() {
clear();
context.drawImage(img, 0, 110, img.width, 175, offset, 0, w - (offset * 2), h);
setTimeout(glitchImg, randInt(250, 1000));
}, 500);
};
var clear = function() {
context.rect(0, 0, w, h);
context.fill();
};
var glitchImg = function() {
for (var i = 0; i < randInt(1, 13); i++) {
var x = Math.random() * w;
var y = Math.random() * h;
var spliceWidth = w - x;
var spliceHeight = randInt(5, h / 3);
context.drawImage(canvas, 0, y, spliceWidth, spliceHeight, x, y, spliceWidth, spliceHeight);
context.drawImage(canvas, spliceWidth, y, x, spliceHeight, 0, y, x, spliceHeight);
}
};
var randInt = function(a, b) {
return ~~(Math.random() * (b - a) + a);
};</script>
</div>
<div class="loading">
<div class="loading-dot"></div>
<div class="loading-dot"></div>
<div class="loading-dot"></div>
<div class="loading-dot"></div>
</div>
</div>
****This part would only be displayed once****