Bootstrap Modal mask popup layer (full version)
Imitating Bootstrap, Bootstrap modal adds fixed to the outer layer, and then uses adaptive top-centering method for the content. The article I’m sharing today does exactly that.
html structure
Considering that the content area needs to be centered, there must be at least one div to position and display the background, and then use a div to center the content. The content area wants to be divided into header, body and footer.
<div class="rs-dialog" id="myModal1"> <div class="rs-dialog-box"> <a class="close" href="#">×</a> <div class="rs-dialog-header"> <h3>标题</h3> </div> <div class="rs-dialog-body"> <p>内容</p> </div> <div class="rs-dialog-footer"> <input type="button" class="close" value="Close" style="float:right"> </div> </div> </div>
Add style
Transparent background is achieved with background and opacity. You can also choose rgba, but browsers IE8 and below do not support it. In order to make a div with fixed position cover the entire window, you can set its top, right, left, and bottom attributes to 0.
When the content area is too long, simulate the browser's vertical scroll bar by setting the overflow attribute of the body (or HTML) to hidden, disabling the browser's real scroll bar from appearing, and then setting the outermost div of the pop-up window. overflow-y:auto, uses the scroll bar of this div to simulate the browser scroll bar.
The scrolling effect when the pop-up window is opened and closed is implemented using css3 transition.
.dialog-open{ overflow-y:hidden !important; } .rs-overlay{ background:#000; opacity:.5; filter: alpha(opacity=50); position: fixed; z-index: 1000; top:0; bottom:0; left:0; right:0; display: none; } .rs-dialog{ display: none; opacity: 0; overflow: hidden; position: fixed; top:0; bottom:0; left:0; right:0; z-index: 1040; -webkit-overflow-scrolling: touch; outline: 0; /*background: rgba(0,0,0,.5);*/ -webkit-transition: opacity .15s linear; -o-transition: opacity .15s linear; transition: opacity .15s linear; } .dialog-open .rs-dialog{ overflow-x:hidden; overflow-y:auto; } .rs-dialog.in{ opacity: 1; } .rs-dialog .rs-dialog-box { -webkit-transform: translate(0, -25%); -ms-transform: translate(0, -25%); -o-transform: translate(0, -25%); transform: translate(0, -25%); -webkit-transition: -webkit-transform 0.3s ease-out; -o-transition: -o-transform 0.3s ease-out; transition: transform 0.3s ease-out; } .rs-dialog.in .rs-dialog-box { -webkit-transform: translate(0, 0); -ms-transform: translate(0, 0); -o-transform: translate(0, 0); transform: translate(0, 0); } .rs-dialog .rs-dialog-box{ position: relative; margin:30px auto; width: 600px; background-color: #ffffff; border-radius:10px; border: 1px solid #999999; border: 1px solid rgba(0, 0, 0, 0.2); -webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5); box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5); } .logged-in .rs-dialog .rs-dialog-box{ margin-top:60px; } .rs-dialog-box a.close{ position: absolute; top: -12px; right: -12px; width: 25px; height: 25px; padding: 0; line-height: 25px; font-size:20px; font-family:Arial,sans-serif; font-weight:bold; text-decoration:none; text-align:center; text-shadow: 0 1px 0 #ffffff; color: #fff; background-color:#8b8b8b; border:2px solid #fff; border-radius: 25px; box-shadow:0 0 3px 1px #999; outline: none; } .rs-dialog-box a.close:hover{ background-color:#444; } .rs-dialog-header{ padding: 20px; border-bottom: 1px solid #e5e5e5; } .rs-dialog-header h3{ font-size: 18px; } .rs-dialog-body{ padding: 20px; line-height: 1.4 } .rs-dialog-body p{ margin-bottom:10px; } .rs-dialog-footer{ padding: 20px; border-top:1px solid #e5e5e5; overflow: hidden; } @media (max-width: 767px) { .rs-dialog .rs-dialog-box { width: auto; margin: 30px 20px; } }
Add control script
Most of them are implemented with css, so the script can control the switch through simple addClass and removeClass.
You can also add the function of clicking outside the pop-up window to close the window.
jQuery(document).ready(function($){ $('body').append('<div class="rs-overlay" />'); $("a[rel='rs-dialog']").each(function(){ var trigger = $(this); var rs_dialog = $('#' + trigger.data('target')); var rs_box = rs_dialog.find('.rs-dialog-box'); var rs_close = rs_dialog.find('.close'); var rs_overlay = $('.rs-overlay'); if( !rs_dialog.length ) return true; // Open dialog trigger.click(function(){ //Get the scrollbar width and avoid content being pushed var w1 = $(window).width(); $('html').addClass('dialog-open'); var w2 = $(window).width(); c = w2-w1 + parseFloat($('body').css('padding-right')); if( c > 0 ) $('body').css('padding-right', c + 'px' ); rs_overlay.fadeIn('fast'); rs_dialog.show( 'fast', function(){ rs_dialog.addClass('in'); }); return false; }); // Close dialog when clicking on the close button rs_close.click(function(e){ rs_dialog.removeClass('in').delay(150).queue(function(){ rs_dialog.hide().dequeue(); rs_overlay.fadeOut('slow'); $('html').removeClass('dialog-open'); $('body').css('padding-right', ''); }); return false; }); // Close dialog when clicking outside the dialog rs_dialog.click(function(e){ rs_close.trigger('click'); }); rs_box.click(function(e){ e.stopPropagation(); }); }); });
Prevent webpage content from shifting
Add the overflow:hidden attribute to the body when opening a pop-up window, causing the scroll bar to disappear. At this time, the content of the web page will move to the right. When the pop-up window opens and the scroll bar appears again, it will Will recover, the visual effect is not friendly. If you know the width of the scroll bar when there is one, adding the padding-right attribute to the body can offset this cheap effect.
Trigger the pop-up window
Finally, according to the above script, the link that triggers the pop-up window is as follows
<a href="#" rel="rs-dialog" data-target="myModal">Launch Demo Modal</a>
rel="rs-dialog" means that this is the link that triggers the pop-up window
data-target="myModal" means that you want to open HTML Pop-up window with ID myModal.
For more articles related to Bootstrap Modal mask pop-up layer (full version), please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

This article explores effective use of Java's Collections Framework. It emphasizes choosing appropriate collections (List, Set, Map, Queue) based on data structure, performance needs, and thread safety. Optimizing collection usage through efficient

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript
