v2.5.2
Giriş yap

[Yardım] Açılıp kapanan div içeriğine transition efekti ekleme

Anonim
587 defa görüntülendi

Bu divin açılıp kapanmasında hiçbir sıkıntı çekmiyorum, ancak açılıp kapanırken transition efekti olsun istiyorum.
Bunu yapan kodları biliyorum ancak eklediğim zaman direkt olarak hata veriyor ve tıklayınca javascript kodu çalışmıyor. Ufak bir örnek ile gösterirseniz çok sevinirim.

var dglow = document.getElementById("searchbar");
function mysearchbar(){
    var style=searchbar.style.display;
    if (style == "block") {
        searchbar.style.display="none";
    }
    else{
        searchbar.style.display="block";
    }
}
webdevyusuf
1458 gün önce

İstediğin örnek sanırım bu

<button id="toggleBtn">Aç / Kapa</button>
<div id="content">
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
#content {
  opacity: 0;
  visibility: hidden;
  position: relative;
  top: 20px;
  transition: 250ms all;
}

#content.active {
  top: 0;
  opacity: 1;
  visibility: visible;
}
const toggleBtn = document.querySelector("#toggleBtn"),
      content = document.querySelector("#content");

toggleBtn.addEventListener("click", () => {
  content.classList.toggle("active");
});