Как запускать скрипт всегда, начиная со старта, когда нажимаете на него из "onClick = 'callMe ();'"? - PullRequest
0 голосов
/ 24 апреля 2020

Почему мой скрипт не хочет запускаться с самого начала? Это всегда продолжается go, когда я пытаюсь повторить его снова. Это мой пример сценария «callMe();», который вызывает всплывающее окно для перечисления и записи во всплывающее окно в виде списка имен из массива, который является этим массивом, созданным до и после перечисления всех из них, всплывающее окно будет автоматически закрываться с помощью установить время ожидания более 3 секунд до закрытия. Тогда вот и возникнет проблема. Когда мы хотим снова запустить сценарий, сценарий всегда запускается или обрабатывает его так же, как и продолжить, все произошло!


Проверьте это из кода моей демонстрационной демонстрации:

var colors = ["(1) Webkit", "(2) \`12345", "(3) Zxcvb", "(4) Asdfg", "(5) Qwerty", "(6) Hdrysa", "(7) Gtdtd", "(8) Fgsru", "(9) Ghfdts", "(10) Rysdn", "(11) Kyixb", "(12) Iyhkj", "(13) Qrsdc"],
		log = document.getElementById("log"),
 		close = document.getElementsByClassName('close')[0].href,
    crntcolor = 0,
    totScn = [];
        function callMe()
        {
    			var arrScn = ["200", "600", "800", "400"],
          		rndScn = getSzeRndm(arrScn)-((crntcolor)+"0");
            	totScn.push(rndScn);

            if (log.textContent.match("Succeed"))
             {
            	log.innerHTML = log.innerHTML.replace(log.innerHTML.split("\|")[1], '');
             };

            if (crntcolor < colors.length)
             {
            	log.innerHTML += "Check Name '"+colors[crntcolor]+"' at "+rndScn+" seconds"+"\n";
              crntcolor++;
            	setTimeout(callMe,rndScn);
             }
            else if (crntcolor == colors.length)
             {
    					var totTme = totScn.reduce((a, b) => a + b);
            	log.innerHTML += "Loading has been Succeed at "+totTme+" seconds";
              var time = 3, rotate = document.getElementsByClassName('rotate')[0], tmp = time;
setInterval(function(){var c=tmp--,m=(c/60)>>0,s=(c-m*60)+''; if(s=='-1'){rotate.textContent="\|"} else if(s=='0'){rotate.textContent='0'} else if(s>='1'){rotate.textContent=s};},1000);
            	setTimeout("goLnk(close);",4800);
             }
            else {};
        }

function goLnk(elmLink) {
  window.location = elmLink;
}

function getSzeRndm(customArray, pickOneAnArray) {
 var text = "",
     sizes = ["2000", "1000", "800", "5000"];

   if (customArray == 0 && pickOneAnArray) {
      if (pickOneAnArray == "8") {text += "8px&2px";}
      else if (pickOneAnArray == "15") {text += "15px&4px";}
      else if (pickOneAnArray == "16") {text += "16px&4px";}
      else if (pickOneAnArray == "18") {text += "18px&4px";};
   }
     else if (!customArray && !pickOneAnArray) {
      text += sizes[Math.floor(Math.random() * sizes.length)];
   }
     else {
      text += customArray[Math.floor(Math.random() * customArray.length)];
  };

   return text;
}
.button {
  font-size: 1em;
  padding: 10px;
  color: #fff;
  border: 2px solid #06D85F;
  border-radius: 20px/50px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease-out;
  font-family: 'Montserrat', sans-serif;
  transform: translateY(-50%);
  text-align: center;
  position: fixed;
  margin-left: 30%;
  width: 30%;
  color: #222;
  top: 50%;
}

.overlay {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity 500ms;
  visibility: hidden;
  opacity: 0;
}
.overlay:target {
  visibility: visible;
  opacity: 1;
}

.popup {
  margin: 5px auto;
  padding: 20px;
  background: #fff;
  border-radius: 5px;
  width: 30%;
	height: 30%;
  position: relative;
  transition: all 5s ease-in-out;
	font-family: monospace;
	font-size: 1em;
	color: #0f0;
	background-color: #111;
	border: 1px solid #030;
	border-radius: 4px;
	overflow: auto;
}

.popup .close {
  position: absolute;
  padding: 1% 5% 15% 20%;
  top: 0px;
  right: 0px;
  transition: all 200ms;
  font-size: 30px;
  font-weight: bold;
  text-decoration: none;
  color: #333;
}
.popup .close:hover {
  color: #06D85F;
}

.rotate {
    -webkit-animation: loading;
	  -moz-animation: loading;
	  -ms-animation: loading;
	  -o-animation: loading;
    animation-duration: 5s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
    animation-fill-mode: both;
    font-family: 'Montserrat', sans-serif;
    text-align: center;
    position: relative;
    left: 11px;
    margin-top: -7%;
}

@keyframes loading {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}

@media screen and (max-width: 2040px){
  .box{
    width: 90%;
    height: 90%;
  }
  .popup{
    width: 90%;
    height: 90%;
  }
}
Let me List

  
    ×

Event information log
====================== |
...