dir.by  
Поиск >>

Компьютер, программы
→
Html & CSS
 How to make a Popup window in a HTML page | Javascript, HTML, CSS 
посмотрели 4335 раз
обновлено: 25 October 2024
Example we look, we test
Source code
  Html     File my.html
<link rel="stylesheet" href="./popup.css" type="text/css" media="screen" />

<script type="text/javascript" src="./popup.js"></script>

<!-- popup background -->
<div class='modal-background'></div>

<!-- popup 1 -->
<div id="my-modal1" class="modal-dialog">
     <div class="modal-title">
          <div class="modal-title-name"><b>My Calculator</b></div>
          <div class="modal-title-close"><button type="button" onclick="CloseDialog(this);">x</button></div>
     </div>
     <div class="modal-content">
          <div>
               <input type='text' value='' size='5'>
               +
               <input type='text' value='' size='5'>
               =
               <font>?</font>
          </div>
          <div style='margin-top:20px'>
               <center><input type='submit' value='Calculate' style='width:100px'></center>
          </div>
     </div>
</div>

<!-- popup 2 -->
<div id="my-modal2" class="modal-dialog">
     <div class="modal-title">
          <div class="modal-title-name"><b>My Notepad</b></div>
          <div class="modal-title-close"><button type="button" onclick="CloseDialog(this);">x</button></div>
     </div>
     <div class="modal-content">
          <div>
               <textarea type='text' value='' rows=18 cols='42'></textarea>
          </div>
          <div style='margin-top:20px'>
               <center><input type='submit' value='Save' style='width:100px'></center>
          </div>
     </div>
</div>

<button onclick='OpenDialog("my-modal1");'>Show Calculator</button>

<button onclick='OpenDialog("my-modal2");'>Show Notepad</button>
  JavaScript     File popup.js
function OpenDialog(dialogId)
{
     document.getElementById(dialogId).style.display = "flex"; // show

     document.querySelector('.modal-background').style.display = "block"; // show
}

function CloseDialog(elem)
{
     elem.closest('.modal-dialog').style.display = "none"; // hide
     document.querySelector('.modal-background').style.display = "none"; // hide
}
  CSS     File popup.css
.modal-dialog {
     display:none;
     position: absolute;
     width: auto;
     pointer-events: none;
     z-index: 2;
     width1: fit-content;
     justify-content:start;
     background-color: #fff;
     flex-direction: column;
     position:fixed;
     left: 50%;
     transform: translateX(-50%);
}

.modal-title {
     display: flex;
     pointer-events: auto;
     flex-direction: row;
     border-bottom: 1px solid rgba(0,0,0,.2);
}

.modal-title-name {
     display:flex;
     justify-content:center;
     width:100%;
     background-color: lightgray;
     padding-left: 0px;
}

.modal-title-close {
     display:flex;
     justify-content:end;
}

.modal-content {
     margin:30px;
     pointer-events: auto;
     background-color: #fff;
     background-clip: padding-box;
}

.modal-background
{
     position:fixed;
     padding:0;
     margin:0;
     top:0;
     left:0;
     width:100%;
     height:100%;
     opacity:0.8;
     background-color:gray;
     z-index:1;
     display:none;
}
Result
 
← Previous topic
Div is always visible when scrolling (position:fixed, position:sticky) | freeze div | HTML
 
Next topic →
Animation of the little man on the spot. For <div>animation, we use CSS styles: "animation", "background-image", "background-position", "keyframes"
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
HTML elements
• HTML tag <a> link to go to another page
• HTML tag <abbr> shows an abbreviated name, if you let the mouse down there will be a pop-up inscription
• HTML tags fieldset and legend. This is a frame with a title
• HTML tag <!-- --> comment
• style="border" in the HTML
<BR>
HTML search for an element, elements
• document.querySelector(...) is a JavaScript method for finding an element from document (i.e. in all HTML)
• yourElement.querySelectorAll(...) is a JavaScript method for finding elements inside another HTML element
<BR>
HTML svg (vector graphics for drawing lines, rectangles, ellipses, ...)
• <svg> vector graphics, drawing a line<line>, rectangle <rect>, circle<circle>, text<text>
<BR>
HTML canvas (drawing pictures, text, shapes)
• HTML <canvas> drawing a rectangle
• HTML drawing <canvas> lines by clicking on the Canvas
• HTML <canvas> we draw pictures
• HTML <canvas> we draw a picture with a rotation
• HTML <canvas> draw a picture with horizontal reflection
• HTML <canvas> we draw a picture and text
• HTML <canvas> draw a picture many times in a rectangle (template)
• HTML <canvas> how to get mouse coordinates ? Determine the position of the mouse.
• HTML <canvas> drawing a snake with lines moveTo, lineTo
CSS
• CSS description
• After modifying the file css , the browser displays old styles over and over again. Why?
• Books to study CSS
CSS flex (the element can stretch or shrink and thus fill the free space)
• What is CSS flex
Freeze
• The header in the table is always visible when scrolling | freeze header in table | HTML
• Div is always visible when scrolling (position:fixed, position:sticky) | freeze div | HTML
Do Popup using HTML and Javascript
• How to make a Popup window in a HTML page | Javascript, HTML, CSS
Motion and animation of pictures
• Animation of the little man on the spot. For <div>animation, we use CSS styles: "animation", "background-image", "background-position", "keyframes"
• Animation of a man in motion (sprite). For <div><img>animation we use CSS styles: "animation", "background-image", "background-position", "keyframes"
• Draw a picture with movement. Use the HTML element<canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval
• Drawing a picture with movement and animation (sprite). Use the HTML element <canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval
Web page on the phone
• I open a web page on my phone in Google Chrome. Why does double-clicking increase the page size?
Layout, page design
• What the Front-end development?
• How to Identify a Device (Tablet, Computer, Phone) Currently Used in JavaScript, HTML
• How to make your site work on a phone, tablet, computer using css media and max-device-width and min-device-width | HTML | CSS
• How to make your website fit in size on your phone, tablet? (HTML meta with attribute name="viewport")
• Correct layout HTML. Bad to use table. You need to use div
• What is Adaptive design? What is responsive design?
• Change the color of the scrollbar for the HTML page. Using CSS
WWW sites for learning
• Sites to explore HTML

  Ваши вопросы присылайте по почте: info@dir.by