jQuery implements simple pop-up window effect

jQuery implements simple pop-up window effect

This article shares the specific code of jQuery to achieve a simple pop-up window effect for your reference. The specific content is as follows

Effect realization diagram

CSS Code

h1,p,h2{
  margin: 0;
  padding: 0;
}
.modal_info{
    display: flex;
    visibility: hidden;
    flex-direction: column;
    align-items:flex-start;
    justify-content: flex-start;
    width: 200px;
    height: auto;
    position: fixed;
    margin:auto;
    background-color: #FFFFFF;
    border-radius: 3px;
    top: 45%;
    left: 50%;
    box-sizing: border-box;
    z-index: 111;
    -webkit-transform: scale(0.7);
    -moz-transform: scale(0.7);
    -ms-transform: scale(0.7);
    transform: scale(0.7);
    opacity: 0;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
}
  .modal_info .head_blue{
  padding: 5px 10px;
  height: auto;
  box-sizing: border-box;
  background: #2262C6;
  font-style: normal;
  font-weight: bold;
  font-size: 18px;
  line-height: 18px;
  color: #FFFFFF;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between !important;
  text-transform:capitalize;
  }
  .modal_info .head_blue h1{
    font-size: 18px;
    color: white;
  } 
  .modal_info .body_main{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 10px;
  background-color: #FFFFFF;
  flex: 1;
  width: 100%;
  box-sizing: border-box;
  }
  .modal_info .bottom_button{
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
  }
  .modal_info .bottom_button div{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 5px;
    box-sizing: border-box;
  }
  
  .modal_info .bottom_button .yes{
    background-color: #2262C6;
    color: #FFFFFF;
  }
  .modal_info .bottom_button .no{
    background-color: #FFFFFF;
    color: #505050;
    border: 1px solid #505050;
  }

  .md-show{
    visibility:visible !important;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform:scale(1);
    transform: scale(1);
    opacity: 1;
  }

HTML code plus jQuery code, pay attention to the referenced CSS and JS
You can download any version of jquery and put it in

<!DOCTYPE html>
<html>
    <head>
        <title>Popup</title>
        <link rel="stylesheet" href="./modal.css" />
    </head>
    <body style="background-color: black;">
        <div class="button_click" style="background-color:#FFFFFF;width: 100px;height: 100px;">Click this</div>
    </body>
    <script type="text/javascript" src="jquery-3.5.1.min.js"></script>
    <script>
        
        function modal_confirm(option){
            var {title,question,content,confirm,cancel,style,btn} = option;
            var yes_confirm,no_cancel;
            btn.forEach(item=>{
                if(item.yes){
                    yes_confirm = item.yes;
                }
                else if(item.cancel){
                    no_cancel = item.cancel;
                }
            }
            )
            if($('.modal_info')){
                $('.modal_info').remove();
            }
            $('body').append(`<div class="modal_info" style="${style?style:''}"></div>`);
            var modal = $('.modal_info');
            modal.append(`<div class="head_blue"><h1>${title?title:'title'}</h1></div>`);
            modal.append(`<div class="body_main"><h1>${question?question:'question'}</h1><p>${content?content:'content'}</p></div>`);
            modal.append(`<div class="bottom_button"><div class="yes">${confirm?confirm:'confirm'}</div><div class="no">${cancel?cancel:'cancel'}</div></div>`);
            setTimeout(() => {
                $('.modal_info').addClass('md-show');
            }, 10);
            $('.yes,.no').on('click',function(){
                if($(this).attr('class')==='yes')
                {
                    yes_confirm();
                }
                else{
                    no_cancel();
                }
                $('.modal_info').removeClass('md-show');
                setTimeout(()=>{
                    this.parentNode.parentNode.remove();
                },300);
            })
        }
        $('.button_click').on('click',function(){
            modal_confirm({
                title:'Title',
                question:'',
                content:'content',
                confirm:'',
                cancel:'cancel',
                style: 'width:200px;height:200px',
                btn:[{
                    yes:function(){
                        console.log('This is confirm');
                        }
                    },
                    {
                    cancel:function(){
                        console.log('This is cancel');
                        }
                    }

                ]
            });
        })
    </script>
</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Two simple pop-up window effect examples implemented by jQuery
  • jQuery implements pop-up window (system prompt box) effect
  • Jquery to achieve custom pop-up example
  • Ideas and codes for implementing pop-up special effects with jquery ui dialog
  • Small and powerful jQuery layer pop-up window plug-in
  • Simple implementation of jQuery pop-up effect
  • jQuery implements the pop-up window centering effect similar to alert()
  • jQuery implements pop-up window function (window is displayed in the center)
  • jQuery makes pop-up window prompt window code sharing
  • Use JQuery's toggle to realize automatic pop-up window after web page loading is completed

<<:  MySQL implementation of lastInfdexOf function example

>>:  XHTML Web Page Tutorial

Recommend

How does Zabbix monitor and obtain network device data through ssh?

Scenario simulation: The operation and maintenanc...

A complete record of a Mysql deadlock troubleshooting process

Preface The database deadlocks I encountered befo...

Vue encapsulation component upload picture component

This article example shares the specific code of ...

Solution to the problem that the mysql8.0.11 client cannot log in

This article shares with you the solution to the ...

CSS solution for centering elements with variable width and height

1. Horizontal center Public code: html: <div c...

Graphical tutorial on installing JDK1.8 under CentOS7.4

Linux installation JDK1.8 steps 1. Check whether ...

How to install MySQL and MariaDB in Docker

Relationship between MySQL and MariaDB MariaDB da...

How to run tomcat source code in maven mode

Preface Recently, I was analyzing the startup pro...

How to implement Mysql scheduled tasks under Linux

Assumption: The stored procedure is executed ever...

CSS uses BEM naming convention practice

When you see a class, what information do you wan...

In-depth explanation of currying of JS functions

Table of contents 1. Supplementary knowledge poin...

Vue achieves seamless carousel effect (marquee)

This article example shares the specific code of ...

W3C Tutorial (5): W3C XML Activities

XML is designed to describe, store, transmit and ...