


jQuery implements click button mask pop-up dialog box (imitation of Tmall's delete dialog box)_jquery
When we are shopping on Tmall, we often encounter that after clicking the delete button or the login button, a dialog box pops up asking you whether to delete or a login dialog box pops up, and we can also see the information from our previous page, just click No, there will be corresponding changes only after operating on the dialog box. The screenshot is as follows (taking Tmall as an example)
As shown in the picture, the above is the rendering of Tmall. In fact, this is achieved through jQuery, and the implementation process is not very complicated, then Now let us take a look at the implementation process.
First is the layout part of the page: delete.html

Prompt when deleting

You really want to delete This record?
< ;/div>
It should be noted that I only added one record, but it can actually simulate multiple Deletion of records. Here we have a three-layer div structure, of which mask and dialog enable us to trigger it through jquery. Next, let’s talk about the layout of css. First, the code: delete.html
@CHARSET "UTF-8";
*{
margin: 0px;
padding: 0px;
}
.divShow{
line-height: 32px;
height: 32px;
background-color: #eee;
width: 280px;
padding -left: 10px;
}
.dialog{
width: 360px;
border: 1px #666 solid;
position: absolute;
display: none;
z-index: 101; // Ensure that this layer is displayed at the top
}
.dialog .title{
background:#fbaf15;
padding : 10px;
color: #fff;
font-weight: bold;
}
.dialog .title img{
float:right;
}
.dialog .content{
background: #fff;
padding: 25px;
height: 60px;
}
.dialog .content img{
float: left;
}
.dialog .content span{
float: left;
padding: 10px;
}
.dialog .bottom{
text-align: right;
padding: 10 10 10 0;
background: #eee;
}
.mask{
width: 100%;
height: 100%;
background: #000;
position: absolute;
top: 0px;
left: 0px;
display: none;
z-index: 100;
}
.btn{
border: #666 1px solid;
width: 65px;
}
In the CSS file, what I need to focus on is the use of z-index. The z-index represents the stacking order of the layers. If the value is higher, it means that it is displayed on the upper layer. The z-index of the mask is 100. The z-index of the dialog is 100. The z-index is 101. The reason why the value is large enough is to ensure that it is absolutely displayed at the top level. The display of the div layer can be controlled by increasing the value.
The next step is the most important js code. Of course, when using jquery, we need to import the jquery package:
delete.js
$(function(){
//Bind the trigger event of the delete button
$("#button1").click(function(){
$(".mask").css("opacity","0.3").show();
showDialog();
$(".dialog").show();
} );
/*
* Set the TOP and left of the prompt dialog box according to the position of the current page on the scroll bar
*/
function showDialog(){
var objw= $(window);//Current window
var objc=$(".dialog");//Current dialog box
var brsw=objw.width();
var brsh=objw.height( );
var sclL=objw.scrollLeft();
var sclT=objw.scrollTop();
var curw=objc.width();
var curh=objc.height();
//Calculate the left margin when the dialog box is centered
var left=sclL (brsw -curw)/2;
var top=sclT (brsh-curh)/2;
/ /Set the dialog box to center
objc.css({"left":left,"top":top});
}
//Triggered when the page window size changes Event
$(window).resize(function(){
if(!$(".dialog").is(":visible")){
return;
}
showDialog();
});
//Register the close image click event
$(".title img").click(function(){
$(".dialog").hide();
$(".mask").hide();
});
//Cancel button event
$( "#noOk").click(function(){
$(".dialog").hide();
$(".mask").hide();
});
//OK button leave
$("#ok").click(function(){
$(".dialog").hide();
$(" .mask").hide();
if($("input:checked").length !=0){
//Note that there cannot be a space in the middle of the filter selector $("input :checked") This is wrong
$(".divShow").remove();//Delete a certain piece of data
}
});
});
It should be noted that the main agent is showDialog() for dynamic confirmation dialog box Show location.

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



Windows 10 users often encounter the situation of opening multiple dialog boxes when using the computer. It is very troublesome to click with the mouse. So what is the shortcut key for switching desktop dialog boxes in Windows 10? To switch windows, just press Alt+Tab. If you want to switch to different desktops after setting up split screen, just press Win+Ctrl+keyboard left/right to quickly switch. , very convenient. List of shortcut keys for switching desktop dialog boxes in Windows 10: 1. Switch windows: [Alt] + [Tab] 2. Task view: [Win] + [Tab], and the page will not fade away when you release the keyboard. 3. Create a new virtual desktop: [Win] + [C

Users using the win10 system have encountered a dialog box when installing software, which is very troublesome. However, in fact, this box can be closed. Perhaps most users cannot operate it, so we have brought a tutorial for you to watch together. See how to close the dialog box that pops up in the win10 installation software. How to close the dialog box that pops up in the win10 installation software: 1. First, press the shortcut key "win+r" to open run, enter "control" and press Enter. 2. Then select "Security and Maintenance" inside. 3. Then click "Change User Account Control Settings" on the left. 4. Then press and hold the small blue square, pull it down to the "Never notify" position, and click OK.

Some friends are always affected by the pop-up search box when using the system, and they don’t know how to close the automatic pop-up search box in Win10. For this reason, a detailed closing method is provided, which can help everyone not to be harassed. How to turn off the automatic pop-up of the search box in win10: 1. First, right-click the pop-up search box and enter the menu. 2. Then click "Search". 3. Then click "Hide" in the pop-up menu. 4. If you want to use it but don’t want to be disturbed, you can click “Show search icon”.

How to implement dialog boxes and modal boxes in Vue? With the continuous development and updating of front-end technology, the development of front-end pages has become more and more complex and diverse. Dialog boxes and modal boxes are elements that often appear in front-end pages and can help us achieve more flexible and diverse interactive effects. In Vue, there are many ways to implement dialog boxes and modal boxes. This article will introduce you to several common implementation methods. 1. Use Vue’s own components. Vue.js provides some built-in components, such as transition and tra.

Recently, when many win7 system users play games on their computers, they report that they always pop up the realtek audio manager automatically, which makes the game's automatic return to the desktop interruption very annoying. How to deal with such a problem? In response to this problem, the editor will introduce to you the detailed solution to the problem that realtek audio manager always pops up when playing games in win7 system. How to solve the problem that realtek audio manager always pops up when playing games in win7? 1. We can click the button on the desktop, which is the lower left corner of the computer. 2. We find an action option there and we can click on it. It will enter the operation interface. 3. In the operation interface, we need to enter msconfig. After entering, tap the action or direct key. 4. in

Techniques and methods of using CSS to implement pop-up special effects when the mouse is hovering. In the design of web pages, we often encounter the need for pop-up special effects when the mouse is hovering. This special effect can improve the user experience and page interactivity. This article will introduce the techniques and methods of using CSS to achieve pop-up effects when the mouse is hovering, and provide specific code examples. 1. Use the transition attribute of CSS3 to realize gradient animation. The transition attribute of CSS3 can realize the gradient animation of elements by setting the appropriate transition time and transition.

Microsoft Edge has a strict policy when it comes to browsers allowing harmful downloads, but there seems to be a slight change in this regard. When you download an "uncommon" file or anything the browser deems harmful, an additional dialog box will appear if you want to keep the download. As shared by insider @Leopeva64 on X (fkaTwitter), this dialog disappears in Dev and Canary versions of the browser. It typically asks the user to confirm whether they want to download the file and provides a brief description of the risks associated with downloading the file. After clicking Keep in the three-dot menu, the file will be downloaded automatically. Check out the differences between the stable version and other versions below: Download "uncommon" files or what Edge thinks

PHP function introduction—array_shift(): Pop the element at the beginning of the array PHP is a widely used scripting language, especially suitable for web development. In PHP, many powerful array functions are provided, one of which is the array_shift() function. This function removes and returns the first element from the beginning of the array, while updating the original array's key value. The syntax of the array_shift() function is as follows: mixedarray_shift(arra
