JavascriptDemo modal window _ javascript skills

Source: Internet
Author: User
I don't know much about it. I should have seen many websites use Jquery plug-ins. I personally think it is not flexible enough. The following Demo supports callback and can be directly referenced by modalDialog. js without any Jquery shadow.
Global. js

The Code is as follows:


Window. js = new myJs (); // to avoid repeated names, add a myJs object to the window object, and then call window. js on the page.
// Js object
Function myJs (){
This. x = 10;
}
// Below we will expand myJs
MyJs. prototype. alert = function (msg) {alert (msg) ;}// A alert method is used to test and call js. alert ('pop-up prompt ');
// Obtain the dom object with the specified Id
MyJs. prototype. $ = function (id) {return document. getElementById (id );}
MyJs. prototype. bodyWidth = document.doc umentElement. clientWidth;
MyJs. prototype. bodyHeight = document.doc umentElement. clientHeight;
MyJs. prototype. body = document. body;


The modalDialog. js file code is as follows:
Code

The Code is as follows:


// Modaldialog
Function modalDialog (){
This. uri = "about: blank"; // address
This. title = null; // title
This. width = 400; // default width
This. height = 300; // default height
This. borderColor = "black"; // border color
This. borderWidth = 2; // Border Width
This. callback = null; // callback Method
This. background = "black ";
This. titleBackground = "silver ";
}
ModalDialog. prototype. url = this. uri; // this is fine without any extension, but you can only prompt that this attribute cannot be found on the page.
ModalDialog. prototype. title = this. title;
ModalDialog. prototype. width = this. width;
ModalDialog. prototype. height = this. height;
ModalDialog. prototype. background = this. background;
ModalDialog. prototype. borderWidth = this. borderWidth;
ModalDialog. prototype. borderColor = this. borderColor;
ModalDialog. prototype. titleBackground = this. titleBackground;
ModalDialog. prototype. callback = this. callback;
// Call back
ModalDialog. prototype. call = function (callback) {if (callback! = Null) callback (this); if (this. callback! = Null) this. callback ();}
// Display
ModalDialog. prototype. show = function (){
Var js = window. js;
// Display details in it
Var x = js. bodyWidth, y = js. bodyHeight;
// First create a layer mask for the entire body
Var zp = "zp"; // mask layer id
Document. body. innerHTML + ="

";
Var mp = "mp"; // modal window layer id
Document. body. innerHTML + ="

"+
// Add the title
(This. title! = Null? "

"+ This. title +"

":" ") +
"

";
}
ModalDialog. prototype. close = function (){
Document. body. removeChild (window. js. $ ("mp "));
Document. body. removeChild (window. js. $ ("zp "));
}


Create modalDialog on the default.html page
Code

The Code is as follows:




Modal window Demo

Related Article

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.