HTML Модальное всплывающее окно

Как сделать простое модальное всплывающее окно для следующего кода. И по щелчку на фоне модальное всплывающее окно не должно исчезать.

<html>
<input type="textarea"></input>
</html>
14
задан Stephane Rolland 12 October 2019 в 11:01
поделиться

2 ответа

Вот простой пример JavaScript:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Basic modal demo</title>
        <style type="text/css">
            body { margin: 0; }
            #shade, #modal { display: none; }
            #shade { position: fixed; z-index: 100; top: 0; left: 0; width: 100%; height: 100%; }
            #modal { position: fixed; z-index: 101; top: 33%; left: 25%; width: 50%; }
            #shade { background: silver; opacity: 0.5; filter: alpha(opacity=50); }
        </style>
    </head>
    <body>
        <div id="shade"></div>
        <div id="modal">
            <textarea rows="5" cols="25"></textarea>
            <button id="close">Close</button>
        </div>

        <p>
            <button id="start">Start</button>
        </p>
        <script type="text/javascript">
            var modal= document.getElementById('modal');
            var shade= document.getElementById('shade');
            document.getElementById('start').onclick= function() {
                modal.style.display=shade.style.display= 'block';
            };
            document.getElementById('close').onclick= function() {
                modal.style.display=shade.style.display= 'none';
            };

            // This code is a workaround for IE6's lack of support for the
            // position: fixed style.
            //
            if (!('maxHeight' in document.body.style)) {
                function modalsize() {
                    var top= document.documentElement.scrollTop;
                    var winsize= document.documentElement.offsetHeight;
                    var docsize= document.documentElement.scrollHeight;
                    shade.style.height= Math.max(winsize, docsize)+'px';
                    modal.style.top= top+Math.floor(winsize/3)+'px';
                };
                modal.style.position=shade.style.position= 'absolute';
                window.onscroll=window.onresize= modalsize;
                modalsize();
            }
        </script>

    </body>
</html>

Есть различные улучшения, которые можно сделать оттуда, например, взлом iframe для исправления IE z-индексирования или инкапсуляции его в многоразовый объект, но это основной способ.

.
16
ответ дан 1 December 2019 в 13:33
поделиться

jQueryUI имеет модальный диалоговый модуль. Он не освобождает управление простым нажатием на фон, как вы просили: http://jqueryui.com/demos/dialog/#modal

<a href="#" class="showModal">Show Modal Box</a>
<div id="modalContents" style="display:none;">
  <textarea>Hello World</textarea>
</div>

--

$(".showModal").click(function(e){
  e.preventDefault();
  $("#modalContents").dialog({bgiframe: true, height: 140, modal: true});
});
2
ответ дан 1 December 2019 в 13:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: