search

Home  >  Q&A  >  body text

Hide/show div on click and scroll

I want to create a hidden search form that appears when we click on the search icon and hides when the user clicks or scrolls.

P粉563831052P粉563831052232 days ago493

reply all(1)I'll reply

  • P粉042455250

    P粉0424552502024-04-07 09:21:30

    You have to use .onclick event in js and change the display and visibility properties in the function. For example:

    document.getElementById("searchIcon").onclick = searchFunction
    function searchFunction(){
       const search = document.getElementById("searchForm");
       search.style.display = "block";
       search.style.visibility = "visible";
    }

    Of course, it should be hidden by default. But display:none is not required and depends on your website.

    reply
    0
  • Cancelreply