简体   繁体   中英

implementing show/hide popup box on mouse click

I have implented the show part properly. But how to implement the hide of popup on click of anything on the page? And moreover there is a link, on click of which this will expand and collapse also.

Any help. Thanks.

  1. Attach an event hanlder to the popup element. On click of that stop event bubbling.

  2. Attach an event handler to document. On click of that hide the popup.

A sample using jQuery

Updated sample

why don't you try this.

function close() {
   document.getElementById("popupBox").style.display="none";
}

In onclick handler, call the above function. For expand and collapse, Mootools provides very simple implementation check it.


function switchElement(elementId) {
   if(document.getElementById(elementId).style.display=="")
   {
   document.getElementById(elementId).style.display="none";
   }
   else
   {
   document.getElementById(elementId).style.display="";
   }
}

expand added to Webbisshh's code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM