jquery modal window with blurry background. Blurred background modals with CSS3
3. An example of a jQuery modal called by link (with Demo)
Most likely, you have already seen a pop-up modal window more than once on the Internet - registration confirmation, warning, reference Information, file upload and more. In this tutorial, I will offer some examples of how to create the simplest modal windows.
Create a simple modal popup
Let's start considering the code of the simplest modal window, which will immediately appearjquery code
Paste the code anywhere in body your page. Immediately after loading the page, without any commands, you will see a window like this:
But the following code will be executed after loading the entire page in the browser. In our example, after loading the page with images, a simple pop-up window will pop up:
Calling a jQuery modal from a link with CSS
The next step is to create modal window when clicking on the link. The background will slowly darken.
You can often see that the login and registration forms are located in such windows. Let's get down to business
To start, let's write html part. We place this code in the body of your document.
Calling a modal window
CSS Code. Either in a separate css file or in
In the jQuery code, we will focus on the position of the modal and the mask, in our case, the gradual darkening of the background.
Attention! Don't forget to include the library in the head of the document!
Connecting the library from the Google site. Well, the jQuery code itself.
jQuery Code
1. Modal window on jQuery "Simple Modal Box"
2. jQuery plugin "LeanModal"
Display content in modal windows. To see the plugin in action on the demo page, click on the link: Sign Up Form or Basic Content.
3. jQuery Plugin "ToastMessage"
Pop-up messages. Plugin in two versions. In one case, messages disappear on their own, after a certain time, in the second implementation, in order to close the message, you must click on the button.
4. Content that pops up in the modal window
Reveal plugin. To see the plugin in action, click on the "Fire A Reveal Modal" button on the demo page.
5. Pretty Dialog Boxes
Click on the cross on the demo page to see the plugin in action.
6. Mootools Modal Window, MooDialog Plugin
7. jQuery popup bar at the top of the screen
8.jQuery Popup
jQuery form plugin feedback in a popup window.
10. MooTools "LightFace" Plugin for Implementing Facebook Dialogs
Facebook-style dialog boxes. In addition to static information, you can put images, frames, Ajax requests into windows. Many settings for the plugin, very powerful tool. Looks very stylish and functional. Follow the links on the demo page to see examples with different content.
11. jQuery modal window
Neat jQuery popup dialog.
12. jQuery Modals
Nice modal popups. Three styles. The demo page has 3 links to call windows.
13. jQuery Modals
Pop-up modal windows of several types. To see the plugin in action, click on the link on the demo page.
15. Pop-up message on top of the page
The message is displayed on top of the page, which, in turn, is dimmed. Click on the "Click me" label on the demo page to see a pop-up message. Clicking on the cross will close it. Implemented with jQuery.
16. Modal window "ModalBox" in javascript
Implementation of modern modal dialog boxes without using pop-ups and page reloads. On the demo page, click on the "Start Demo" button to see how the script works.
17. "Leightbox" plugin using the Prototype library
Plugin for displaying content in modal windows.
Modal windows are an integral part of modern web design, with their help, the developer can resort to the method of looping on one page and not redirecting the visitor to auxiliary pages. In this tutorial, we're going to look at how to create awesome modal windows with a blurry background for a website using jQuery and CSS3. Thanks to these rules, we will create a blurry background when the window appears, which will tie the visitor's gaze only to the necessary information on the site.
Blurred background modals with CSS3
Economic news is the best only here: Drobakha
The animation of the window will be set in such a way that when you click on the appearance button, the window will animate from top to bottom, while automatically increasing the background blur.
Step 1: HTML
We will have a container that will contain: title, description, then we add a class for the button with the class toggleModal to open a modal window:
header
Description
Title for the window
Tabs are a very interesting and convenient thing when creating a site, it allows you to properly organize information, while saving some space on the site.
Then we need to add a class modal is-active, this class will be responsible for calling the modal window, modal_header is responsible for the title and its styling of the window.
Step 2: CSS
Now let's move on to styling, the first step is the class button, which will be responsible, you guessed it, for the buttons on the site, we set the correct display parameters for it:
Button ( background: none; background-clip: padding-box; display: inline-block; border: 0; user-select: none; -webkit-touch-callout: none; -webkit-appearance: button; -webkit-user -select: none; -moz-user-select: none; -ms-user-select: none; )
Container ( position: relative; margin:0 auto; max-width: 960px; box-sizing: border-box; padding-top: 40px; )
article ( background: #fff; padding: 20px; margin-bottom: 40px; border-radius: 5px; ) .modal ( display: none; position: fixed; top: 50%; width: 100%; height: auto; margin -top: -150px; background-color: $color-white; border-radius: 3px; z-index: 999; box-shadow: 0px 1px 3px 0px darken($color-bg, 10%); @media #( $small) ( left: 50%; margin-left: -260px; max-width: 520px; ) &.is-active ( display: block; animation: 1s linear slide; ) .inner ( position: relative; padding: 20px ; ) ) .modal__header ( border-bottom: 1px solid darken($color-bg, 5%); ) .modal__footer ( text-align: center; button ( display: inline-block; ) )Styles are quite simple, they are stored in a separate file and should not cause difficulties when editing them for a developer who has ever encountered CSS.
Step 3JS
Our last, but no less important, will be the automatic blurring of the background when the menu appears, as well as the clickability of links, small rules will help us with this. JS:
$("body").addClass("is-blurred"); $(".toggleModal").on("click", function (event) ( event.preventDefault(); $(".modal").toggleClass("is-active"); $("body").toggleClass ("is-blurred"); ));
As a result, we get wonderful modal windows that are pleasing to the eye of the visitor and do not clutter up your design.
It is quite common to see modal windows on websites, and all of them are used for different tasks. In fact, this is a rather powerful tool that allows you to make the site interface more interactive and convenient. For example, modal windows can be used for various forms, such as an authorization form, feedback form, product ordering, and you never know.
In this post, we will look at an example of how to make a simple modal window using JQuery and CSS. The peculiarity of this example is that it is not required here, well, with the exception of the JQuery library itself.
We place the code of the modal window on the page:
As you can see from the markup, the block of the modal itself is a div with the id= attribute modal_form, which contains the span element with id= modal_close. This element will serve as a button to close the modal window, in addition, below the block there is a div block with the id= attribute overlay, which also serves to darken the background. The modal window will be opened by a link, with the class modal.
CSS for the modal window
#modal_form ( width: 300px; height: 300px; border-radius: 5px; border: 3px #000 solid; background: #fff; position: fixed; top: 45%; left: 50%; margin-top: -150px; margin-left: -150px; display: none; opacity: 0; z-index: 5; padding: 20px 10px; ) #modal_form #modal_close ( width: 21px; height: 21px; position: absolute; top: 10px; right: 10px; cursor: pointer; display: block; ) #overlay ( z-index:3; position:fixed; background-color:#000; opacity:0.8; -moz-opacity:0.8; filter:alpha(opacity=80) ; width:100%; height:100%; top:0; left:0; cursor:pointer; display:none; )
For modal_form we set a fixed width and height, and then centered the position to the center of the screen. For the modal window's underlay ( overlay) we set the size to the width of the screen, fill with transparency, and also hide it by default. special moment with z-index, the modal must have the largest of all elements on the page, and the skin must have the largest of all elements except the modal itself.
Now to the most basic, this is the javascript code. For the modal window, two main events will be used, this is its opening - clicking on an element with the class modal, in our case this is a link, and closing the modal window is a click on the cover ( overlay), or clicking on the close button, in our case it is a span element with id= modal_close.
$(document).ready(function() ( $(".modal").click(function(event)( event.preventDefault(); $("#overlay").fadeIn(400, // animate the cover display function ()( // next show the mod. window $("#modal_form") .css("display", "block") .animate((opacity: 1, top: "50%"), 200); )); )); // close the modal window $("#modal_close, #overlay").click(function()( $("#modal_form") .animate((opacity: 0, top: "45%"), 200, // decrease transparency function()( // after animation $(this).css("display", "none"); // hide window $("#overlay"). fadeOut(400); // hide background ) ); )); ));
With animate we change the vertical position top as well as transparency opacity, and with the help of this we get an interesting effect. A similar effect is used both when the window is opened and when it is closed. The difference is that the order of applying properties for blocks is changed, thereby visualizing the opening and closing of the window.
Talking about the various techniques of site building, it would be absurd not to talk about some of the ways to create modal windows. We will not talk about the purpose, usefulness and emerging problems of using pop-up, modal windows. Let's take a look at just one of the many examples of creating such windows.
There are situations when it is not possible to use special plugins, for example, such as and, so it's worth understanding how you can create your own.
Let's see how to do it:
HTML
Let's start by adding tags with the following attributes:
- href - #?w=500 specifies the width of the window
- rel is a unique attribute for each window
- class="poplight" – class for showing a popup window
< a href= "#?w=500" rel= "popup_name" class = "poplight" >See Window in action - Width = 500px a> |
See Window in action - Width = 500px
Next, we need to create the inline markup for the popup. You can place it anywhere on the page, for example, at the bottom of the content. Note that the popup id matches the attribute rel tag
This will link the link and the popup together.
header
Any text you like
And so, we figured out the placement of our window on the page, now let's decorate it with styles, give it a decent look, so to speak.
CSS Layout
For greater clarity, I have written some explanations for the style parameters of our window. Since popups can have different sizes, we do not specify in CSS popup_block the edges of the window, calculate the required size, this is just the task for .
#fade ( display : none ; /*--default is hidden--*/ background : rgba (7 , 87 , 207 , 0.8 ) ; position : fixed ; left: 0 top : 0 ; width : 100% height : 100% opacity: .80 z-index : 9999 ; ) .popup_block ( display : none ; /*--hidden by default--*/ background : #fff ; padding: 20px border : 8px solid rgb (134 , 134 , 134 ) ; float : left ; font-size : 85% position : fixed ; top : 50% ; left : 50% color : #000 ; max-width : 750px min-width : 320px ; height : auto ; z-index : 99999 ; /*--CSS3 box-shadow--*/-webkit-box-shadow: 0px 0px 20px #000 ; -moz-box-shadow: 0px 0px 20px #000 ; box-shadow : 0px 0px 20px #000 ; /*--CSS3 corner rounding--*/-webkit-border-radius: 12px ; -moz-border-radius: 12px ; border-radius : 12px ; ) .popup_block p ( font-weight : 400 ; padding : 0 ; margin : 0 ; color : #000 ; line-height : 1.6 ; ) .popup_block h2 ( margin : 0px 0 10px ; color : rgb (43 , 43 , 43 ) ; font-weight : 400 ; text-align : center ; text-shadow : 1px 1px 2px #0D0C0C ; ) /* form the close button */.close ( background-color : rgba (61 , 61 , 61 , 0.8 ) ; border : 2px solid #ccc ; height : 25px ; line-height : 20px ; position : absolute ; right : -17px ; font-weight : bold ; text-align : center ; text-decoration : none ; padding : 0 ; top : -17px ; width : 25px ; -webkit-border-radius: 50% ; -moz-border-radius: 50% ; -ms-border- radius: 50% ; -o-border-radius: 50% ; border-radius : 50% ; -moz-box-shadow: 1px 1px 3px #000 ; -webkit-box-shadow: 1px 1px 3px #000 ; box- shadow : 1px 1px 3px #000 ; ) .close : before ( color : rgba (255 , 255 , 255 , 0.9 ) ; content : "X" ; font-size : 12px ; text-shadow : 0 -1px rgba (0 , 0 , 0 , 0.9 ) ; ) .close : hover ( background-color : rgba (252 , 20 , 0 , 0.8 ) ; ) .shadow ( box-shadow : 4px 4px 10px #857373 ; -webkit-box-shadow: 4px 4px 10px #857373 ; -moz-box-shadow: 4px 4px 10px #857373 ; padding : 0 ; ) /*--fixed positioning for IE6--*/* html #fade ( position : absolute ; ) * html .popup_block ( position : absolute ; ) |
#fade ( display: none;/*--hidden by default--*/ background: rgba(7, 87, 207, 0.8); position: fixed; left: 0; top: 0; width: 100%; height: 100%; opacity: .80; z-index: 9999; ) .popup_block ( display: none; /*--hidden by default--*/ background: #fff; padding: 20px; border: 8px solid rgb(134, 134, 134); float: left; font-size: 85%; position: fixed; top: 50%; left: 50%; color: #000; max-width: 750px; min-width: 320px; height: auto ; z-index: 99999; /*--CSS3 box-shadow--*/ -webkit-box-shadow: 0px 0px 20px #000; -moz-box-shadow: 0px 0px 20px #000; box-shadow: 0px 0px 20px #000; /*--CSS3 corner rounding--*/ -webkit-border-radius: 12px; -moz-border-radius: 12px; border-radius: 12px; ) .popup_block p ( font-weight: 400; padding: 0; margin: 0; color: #000; line-height: 1.6;) : center; text-shadow: 1px 1px 2px #0D0C0C; ) /* form the close button */ .close ( backgro und-color: rgba(61, 61, 61, 0.8); border: 2px solid #ccc; height: 25px; line-height: 20px; position: absolute; right: -17px; font-weight: bold; text-align: center; text-decoration: none; padding: 0; top: -17px; width: 25px -webkit-border-radius: 50%; -moz-border-radius: 50%; -ms-border-radius: 50%; -o-border-radius: 50%; border-radius: 50% -moz-box-shadow: 1px 1px 3px #000; -webkit-box-shadow: 1px 1px 3px #000; box-shadow: 1px 1px 3px #000; ) .close:before ( color: rgba(255, 255, 255, 0.9); content: "X"; font-size: 12px; text-shadow: 0 -1px rgba(0, 0, 0, 0.9); ) .close:hover ( background-color: rgba(252, 20, 0, 0.8); ) .shadow ( box-shadow:4px 4px 10px #857373; -webkit-box-shadow:4px 4px 10px #857373; -moz- box-shadow:4px 4px 10px #857373; padding:0; ) /*--fixed positioning for IE6--*/ *html #fade ( position: absolute; ) *html .popup_block ( position: absolute; )
With the formation of the window and its appearance with css, I think there will be no special difficulties. Styles can be written directly on HTML page, between tags
and, or you can take it to separate file your styles, usually this file style.css, or something like that.jquery setup
For the full operation of the modal window, you need to connect jQuery, who are not familiar with the work of this library, you can read.
Well, we'll move on. you can most latest version jQuery from the library website, or use a separate file hosted in the bowels of Google, connecting it to the document, in the section before the closing tag