I am in the process of building my own website and I've been working on implementing a button that can toggle the visibility of a specific div element. While the functionality is there, I really want to incorporate an animation to enhance it.
I attempted to replace the "block"
with fadeIn()
and the "none"
with fadeOut()
, but unfortunately, that did not yield the desired results.
Does anyone have any suggestions or ideas on how I can achieve this?
function pcsh1() {
var x = document.getElementById("pc1");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
<button onclick="pcsh1()">Show / Hide PC 1</button>
<div id="pc1">
<textarea rows="2" cols="20" placeholder="PC Name" class="pcbox">PC Name: </textarea>
<textarea rows="2" cols="20" placeholder="Alignment" class="pcbox">Alignment: </textarea>
<textarea rows="2" cols="20" placeholder="Max HP" class="pcbox">Max HP: </textarea>
<textarea rows="2" cols="20" placeholder="Current HP" class="pcbox">Current HP: </textarea>
</div>
Although the current output serves its purpose, implementing an animation would greatly improve the overall user experience.