美好的一天每個人我都有一個工作我的加載只有一次麻煩。因爲當我刷新頁面或如果我要去另一個頁面它總是加載。 這裏是到目前爲止我的代碼:加載需要只工作一次
JS
<!--Auto load the on overlay function-->
<script>
window.onload = function openNav() {
document.getElementById("myNav").style.width = "100%";
splashScreen();
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
,這裏是我的js功能爲我splashscreen.js
//use onload when in your html the context is not inside
//the <header>
//create a splashScreen function
function splashScreen(){
//get the element on the html side with the id of "skip"
var skipButton = document.getElementById("skip");
//counter for the countdown
var counter = 5;
//create an element <p>
var newElement = document.createElement("p");
newElement.innerHTML = "Skip this 5 seconds";
var id;
skipButton.parentNode.replaceChild(newElement, skipButton);
id = setInterval(function(){
counter--;
if(counter < 0){
//replace the newElement on else condition statement
newElement.parentNode.replaceChild(skipButton, newElement);
clearInterval(id);
} else {
newElement.innerHTML = "You can skip this in " + counter.toString() + " seconds.";
}
}, 1000);
}
,這是我怎麼稱呼它在我的html
<html>
<body>
<!--SplashScreen JS-->
<script src="<?php echo base_url('assets/public/js/splashscreen.js');?>">
</script>
我這樣做了'''const NAME =「once」; window.onload = function openNav(){ document.getElementById(「myNav」)。style.width =「100%」;如果(this.NAME!== NAME){ splashScreen(); } else { alert(this.name); }我的導航欄上有''' –
我有畫廊,當我去我們團隊時,我們的團隊仍然彈出 –
'this.NAME'與'window'的'name'屬性不一樣。查看更新後的帖子 – guest271314