Javascript jQuery plug-in exercises

Source: Internet
Author: User

Simplified Plugin:
SimplePlugin.htm:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> simplified plug-in </title>
<Script type = "text/ecmascript" src = "../js/jquery-1.2.6.js"> </script>
<Script type = "text/ecmascript" src = ".../js/jquery. SimplePlugin. js"> </script>
<Script type = "text/ecmascript">
$ (Function (){
$ ("Input"). click (function (){
$ ("Body"). dialog ();
})
});
Function f (){
$ ("Body"). find ("# MaskID"). hide (1000 );
$ ("Body"). find ("# DivDialog"). hide (1000 );
}
</Script>
</Head>
<Body>
<Input type = "button" value = "hi plugin"/>
</Body>
</Html>


Jquery. SimplePlugin. js:

Copy codeThe Code is as follows:
$. Fn. dialog = function (){
This. MaskDiv = function () // customize a function
{
// Create a masked background. The transparency is not set here for simplicity. ZIndex determines the mask.
$ ("Body"). append ("<div ID = MaskID> </div> ");
$ ("Body"). find ("# MaskID"). width ("888px"). height ("666px ")
. Css ({position: "absolute", top: "0px", left: "0px", background: "# ccc", zIndex: "10000 "});
}
This. MaskDiv (); // call a custom function.
$ ("Body "). append ("<div ID = DivDialog style = 'display: none '> <ul> <li> prompt </li> </ul> <input type = 'button' value = 'close' onclick = 'f (); '/> </div> ");
Var obj = $ ("body"). find ("# DivDialog ");
Obj. width ("200px"). height ("200px ");
Obj.css ({position: "absolute", top: "100px", left: "100px", background: "# FFCC66", zIndex: "10001 "}). show ("slow ");

Return this;
}

Complete plug-ins:
Myplugin.html:

Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> exercise jQuery plug-in </title>
<Script type = "text/ecmascript" src = "../js/jquery-1.2.6.js"> </script>
<Script type = "text/ecmascript" src = "../js/jquery. firstplugin. js"> </script>
<Script type = "text/ecmascript" src = "../js/jquery. dialog. js"> </script>
<Style type = 'text/css '>
* {Padding: 0; margin: 0}/* this row style must be added. Otherwise, a BUG may occur. */

# MyDiv {
Position: absolute;
Width: 200px;
Height: 200px;
Font-size: 12px;
Background: #666;
Border: 1px solid #000;
Z-index: 10001;
Display: none;
Text-align: center;
}
</Style>
<Script type = "text/ecmascript">
$ (Document). ready (function (){
$ ("Input"). click (function (){
$ ("Body"). dialog ();
})
})
</Script>
</Head>

<Body>
<Div>
<Input type = "button" value = "hi plugin"/>
</Div>
</Body>
</Html>

Jquery. dialog. js:
Copy codeThe Code is as follows:
// JScript File
$. Fn. dialog = function (){
This. MaskDiv = function () // customize a function
{
Var wnd = $ (window), doc = $ (document );
If (wnd. height ()> doc. height () {// when the height is less than one screen
WHeight = wnd. height ();
} Else {// when the height is greater than one screen
WHeight = doc. height ();
}
// Create a mask background
$ ("Body"). append ("<div ID = MaskID> </div> ");
$ ("Body"). find ("# MaskID"). width (wnd. width (). height (wHeight)
. Css ({position: "absolute", top: "0px", left: "0px", background: "# ccc", filter: "Alpha (opacity = 90 );", opacity: "0.3", zIndex: "10000 "});
}
This. sPosition = function (obj) // customize a function with Parameters
{
Var MyDiv_w = parseInt (obj. width ());
Var MyDiv_h = parseInt (obj. height ());

Var width = parseInt ($ (document). width ());
Var height = parseInt ($ (window). height ());
Var left = parseInt ($ (document). scrollLeft ());
Var top = parseInt ($ (document). scrollTop ());

Var Div_topposition = top + (height/2)-(MyDiv_h/2); // calculate the top margin
Var Div_leftposition = left + (width/2)-(MyDiv_w/2); // calculate the left margin
Return Array (Div_topposition, Div_leftposition );
}
This. MaskDiv ();
$ ("Body "). append ("<div ID = DivDialog style = 'display: none'> <ul> <li> prompt </li> </ul> </div> ");
Var obj = $ ("body"). find ("# DivDialog ");
Obj. width ("200px"). height ("200px ");
PosT = this. sPosition (obj );
Obj.css ({position: "absolute", top: PosT [0] + "px", left: PosT [1] + "px", background: "# FFCC66", zIndex: "10001 "}). show ("slow ");
Return this;
}

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.