Sorry I’m pretty hopeless with Javascript. I have a script that shows a popup which then fades out. But I cannot get it to reset. The code as it stands only works once.
function myFunction$users5() {
var pop = document.getElementById("myPopup$users5");
pop.classList.add("show");
setTimeout(function() {
$('#myPopup$users5').fadeOut('fast', function() {
pop.classList.remove("show");
});
}, 3000);
}
<div class="popup" onclick="myFunction'.$users5.'()"><img src="unlovesm.png" style="float:right"><span class="popuptext" id="myPopup'.$users5.'">Login to Like.</span></div>
The popup shows and fades out correctly but thats it. Clicking the div again doesn’t show the popup a second time.
2
Answers
I don’t use jQuery, but it looks like you tell it to fade out your div, but never have it fade it back in again. One way of dealing with that is to use jQuery’s fadeToggle() and match it up with the classList.toggle().
To fix this, you can modify your myFunction$users5() to toggle the visibility of the popup by checking if the "show" class is already present. Here’s how you can do it: