Sample Code of js confirmation deletion dialog box Effect

Source: Internet
Author: User

The effect is as follows:



Cssfile delcss.css

The Code is as follows:
Copy codeThe Code is as follows:
* {Margin: 0; padding: 0 ;}
# Div1 {width: 300px; height: 100px; border-radius: 10px; background: # f60; box-shadow: 5px 5px 10px # ccc; position: absolute; left: 50%; margin-left:-150px; z-index: 2; opacity: 0; filter: alpha (opacity: 0); display: none ;}
# Div1 h3 {height: 20px; background: # 60f ;}
# Overlay {width: 100%; height: 100%; background: # ccc; position: absolute; left: 0; top: 0; opacity: 0; z-index: 1; display: none ;}
# CloseConfirm {width: 80px; height: 20px; line-height: 20px; background: # ccc; border-radius: 5px; display: block; text-decoration: none; color: #000; text-align: center; position: absolute; bottom: 10px; right: 10px ;}
# TrueConfirm {width: 80px; height: 20px; line-height: 20px; background: # ccc; border-radius: 5px; display: block; text-decoration: none; color: #000; text-align: center; position: absolute; bottom: 10px; right: 100px ;}
# ConfirmCon {text-align: center; color: # ccc; height: 40px; line-height: 40px ;}

Js file confirmPop. js

The Code is as follows:
Copy codeThe Code is as follows:
Function ConfirmPop (delObj, confirmMain, overlay, binkTitle, closeConfirm, trueConfirm ){
This. oDelObj = document. getElementById (delObj );
This. oDiv = document. getElementById (confirmMain );
This. oOverlay = document. getElementById (overlay );
This. oTitle = document. getElementById (binkTitle );
This. oCloseConfirm = document. getElementById (closeConfirm );
This. oTrueConfirm = document. getElementById (trueConfirm );
This. oConStart = 0;
This. oConItarget = 0;
This. init ();
}
ConfirmPop. prototype = {
Init: function (){
This.oconstartpaiparseint(document.doc umentElement. clientHeight-this.oDiv.offsetHeight)/2-100 );
This.oconitargetpaiparseint(document.doc umentElement. clientHeight-this.oDiv.offsetHeight)/2-70 );
This. oDiv. style. top = this. oConStart + 'px ';
Document. title = this. oConStart + ',' + this. oConItarget;
Var _ this = this;
This. oDelObj. onclick = function (){
_ This. confirmShow ();
}
This. oOverlay. onclick = function (){
_ This. titleBink ();
}
This. oCloseConfirm. onclick = this. oTrueConfirm. onclick = function (){
_ This. confirmHide ();
}

},
ConfirmShow: function (){
This. oOverlay. style. display = 'block ';
This. oDiv. style. display = 'block ';
StriveMove (this. oOverlay, {opacity: 30 });
StriveMove (this. oDiv, {top: this. oConItarget, opacity: 100 })
},
TitleBink: function (){
Var _ this = this;
Var iLightTimer = null;
Var I = 0;
ILightTimer = setInterval (function (){
If (I % 2 ){
_ This. oTitle. style. background = '# 60f ';
} Else {
_ This. oTitle. style. background = '# ccc ';
}
I ++;
If (I> 5 ){
ClearInterval (iLightTimer );
}
}, 50)
},
ConfirmHide: function (){
StriveMove (this. oOverlay, {opacity: 0 });
This. oOverlay. style. display = 'none ';
StriveMove (this. oDiv, {top: this. oConStart, opacity: 0 });
}

}
Function striveMove (obj, json, fn) {clearInterval (obj. iTimer); obj. iTimer = setInterval (function () {var bStop = true; for (var attr in json) {var iCur = 0; if (attr = 'opacity ') {iCur = Math. round (parseFloat (getStyle (obj, attr) * 100);} else {iCur = parseInt (getStyle (obj, attr ));} var iSpeed = (json [attr]-iCur)/8; iSpeed = iSpeed> 0? Math. ceil (iSpeed): Math. floor (iSpeed); if (attr = 'opacity ') {obj. style. filter = 'Alpha (opacity: '+ (iCur + iSpeed) +') '; obj. style. opacity = (iCur + iSpeed)/100 ;}else {obj. style [attr] = iCur + iSpeed + 'px ';} if (iCur! = Json [attr]) {bStop = false;} if (bStop) {clearInterval (obj. iTimer); if (fn) {fn () ;}}, 30)} function getStyle (obj, attr) {return obj. currentStyle? Obj. currentStyle [attr]: getComputedStyle (obj, false) [attr];}

Usage

1. Import files
Copy codeThe Code is as follows:
<Link rel = "stylesheet" type = "text/css" href = "delcss.css"/>
<Script src = "confirmPop. js"> </script>

2. Call Method
Copy codeThe Code is as follows:
<Script>
Window. onload = window. onresize = function (){
New ConfirmPop ('btn ', 'div1', 'overlay', 'title', 'closeconfirm', 'trueconfirm ');
}
</Script>

3. Make preparations
Copy codeThe Code is as follows:
<Div id = "div1">
<H3 id = "title"> <Div id = "confirmCon">
Are you sure you want to delete it?
</Div>
<A href = "###" id = "trueConfirm"> OK </a>
<A href = "###" id = "closeConfirm"> cancel </a>
</Div>
<Div id = "overlay"> </div>

This Code provides space and self-written div code. You can enter the deleted address in tag a in the confirmation box. Click "OK" to go to the page deletion method.

This code can be put anywhere. No space occupied. The author is sharp.

4. Fuse and trigger
Copy codeThe Code is as follows:
<A id = "btn"> </a>

Add id = "btn" to the delete icon to trigger the delete effect.

If you want to modify the style, you can modify and adjust it in css.

Summary:Such js deletion is more beautiful than the pop-up box of the browser. The author writes this effect in just 3 K js, which is really amazing.

Ps, I just used it.

Disadvantage: Only one content can be deleted. Because all of them are id-specific and single.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.