简体   繁体   English

在javascript中将鼠标移出时,模态消失

[英]modal disappear when mouse out in javascript

when i mouseover on button ,modal should appear.When i try to select any values inside the modal ,modal immediately disappears. 当我将鼠标悬停在按钮上时,应该出现模态。当我尝试选择模态内的任何值时,模态立即消失。

 <button class="modalShow" onMouseOver={this.showModal} onMouseOut={this.closeModal}  >
          Show Modal
          </button>

            <div class="modal modalView"  id="myModal"   >
            <div class="modalDialog modalClass">
                <div class="modalContent">
                    <div class="header">
                        <ul class="drop">  
                            <li>
                              <input type="radio" id="first" name="first" value="1"   />
                              <label>first</label>
                            </li>
                             <li>
                              <input type="radio" id="second" name="second" value="2"   />
                              <label>second</label>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            </div>

     showModal= event => {    
        document.getElementById("myModal").style.display = "block"; 

        /* logic***/
    }

close modal function on button mouseout . 关闭鼠标上的模态功能。

closeModal= event => {  
        document.getElementById("myModal").style.display  = "none";  
    }

Your question is not clear.So anybody dont understand what did you ask.But i prepare a solution for you even so.May be this sample is enough for you. 您的问题尚不清楚,因此任何人都不明白您的要求。但是即使如此,我也为您准备了解决方案。也许这个示例对您来说足够了。

This code has 2 options : 此代码有2个选项:

  • opening modal with pressing a button. 按下按钮即可打开模式。
  • and When selecting anywhere on modal , modal will close. 当在modal上选择任意位置时,modal将关闭。

    You can check it : 您可以检查一下:

 // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getElementById("myBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks the button, open the modal btn.onclick = function() { modal.style.display = "block"; } // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } function closeModal() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } 
  body { font-family: Arial, Helvetica, sans-serif; } /* The Modal (background) */ .modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ padding-top: 100px; /* Location of the box */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0, 0, 0); /* Fallback color */ background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */ } /* Modal Content */ .modal-content { background-color: #fefefe; margin: auto; padding: 20px; border: 1px solid #888; width: 80%; } /* The Close Button */ .close { color: #aaaaaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: #000; text-decoration: none; cursor: pointer; } 
 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <h2>Modal Example</h2> <!-- Trigger/Open The Modal --> <button id="myBtn">Open Modal</button> <!-- The Modal --> <div id="myModal" class="modal"> <!-- Modal content --> <div onClick="closeModal()" class="modal-content"> <span class="close">&times;</span> <p>Some text in the Modal..</p> </div> </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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