Ich versuche, eine Funktion nicht vorübergehend (24 Stunden) nach einmaligem Klicken zu arbeiten.Eine Funktion für 24 Stunden verzögern
Ich habe versucht, das Ganze in einer Funktion setTimeout() Umwickeln der ms bis zu einem Tag zählen Einstellung, die 86400000.
ist (siehe Ausgabe here)
$('.dates').click(function() {
var rand = Math.floor(Math.random() * 100 + 1);
var flows = ["flowOne", "flowTwo", "flowThree"];
var colors = ["colOne", "colTwo", "colThree", "colFour", "colFive", "colSix"];
var timing = (Math.random() * (1.3 - 0.3) + 1.6).toFixed(1);
// Animate Particle
$('<div class="particle part-' + rand + ' ' + colors[Math.floor(Math.random() * 6)] + '" style="font-size:' + Math.floor(Math.random() * (30 - 22) + 22) + 'px;"><i class="fa fa-heart-o"></i><i class="fa fa-heart"></i></div>').appendTo('.particle-box').css({
animation: "" + flows[Math.floor(Math.random() * 3)] + " " + timing + "s linear"
});
$('.part-' + rand).show();
// Remove Particle
setTimeout(function() {
$('.part-' + rand).remove();
}, timing * 1000 - 100);
$('#output').html(function(i, val) {
return parseInt(val, 10) + 1;
console.log(val);
});
return false;
});
Gibt es etwas, was ich bin fehlt ?
Wie verzöge ich die Funktion so, dass sie nur alle 24 Stunden aufgerufen werden kann?
Bei Verzögerungen, die so lange dauern, könnten Sie die Verwendung von Cookies oder localStorage in Betracht ziehen, um die Persistenz zu unterstützen. –
@PatrickRoberts Wie? – user3421197
Ich weiß es nicht, weil Sie keine klare Aussage darüber gemacht haben, was falsch ist und was Ihr gewünschtes Ergebnis ist. –