Jquery plug-in exercises

Source: Internet
Author: User

Simplified Plugin:

Simpleplugin.htm:

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Title> simplified plug-in </title>
  5. <SCRIPT type = "text/ecmascript" src = "../JS/jquery-1.2.6.js"> </SCRIPT>
  6. <SCRIPT type = "text/ecmascript" src = ".../JS/jquery. simpleplugin. js"> </SCRIPT>
  7. <SCRIPT type = "text/ecmascript">
  8. $ (Function (){
  9. $ ("Input"). Click (function (){
  10. $ ("Body"). Dialog ();
  11. })
  12. });
  13. Function f (){
  14. $ ("Body"). Find ("# maskid"). Hide (1000 );
  15. $ ("Body"). Find ("# divdialog"). Hide (1000 );
  16. }
  17. </SCRIPT>
  18. </Head>
  19. <Body>
  20. <Input type = "button" value = "Hi plugin"/>
  21. </Body>
  22. </Html>

Jquery. simpleplugin. JS:

  1. $. FN. Dialog = function (){
  2. This. maskdiv = function () // customize a function
  3. {
  4. // Create a masked background. The transparency is not set here for simplicity. Zindex determines the mask.
  5. $ ("Body"). append ("<Div id = maskid> </div> ");
  6. $ ("Body"). Find ("# maskid"). Width ("888px"). Height ("666px ")
  7. . CSS ({position: "absolute", top: "0px", left: "0px", Background: "# CCC", zindex: "10000 "});
  8. }
  9. This. maskdiv (); // call a custom function.
  10. $ ("Body "). append ("<Div id = divdialog style = 'display: none '> <ul> <li> prompt </LI> </ul> <input type = 'button' value = 'close' onclick = 'f (); '/> </div> ");
  11. VaR OBJ = $ ("body"). Find ("# divdialog ");
  12. OBJ. Width ("200px"). Height ("200px ");
  13. Obj.css ({position: "absolute", top: "100px", left: "100px", Background: "# ffcc66", zindex: "10001 "}). show ("slow ");
  14. Return this;
  15. }

Complete plug-ins:

Myplugin.html:

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
  5. <Title> exercise jquery plug-in </title>
  6. <SCRIPT type = "text/ecmascript" src = "../JS/jquery-1.2.6.js"> </SCRIPT>
  7. <SCRIPT type = "text/ecmascript" src = "../JS/jquery. firstplugin. js"> </SCRIPT>
  8. <SCRIPT type = "text/ecmascript" src = "../JS/jquery. Dialog. js"> </SCRIPT>
  9. <Style type = 'text/CSS '>
  10. * {Padding: 0; margin: 0}/* this row style must be added. Otherwise, a bug may occur. */
  11. # Mydiv {
  12. Position: absolute;
  13. Width: 200px;
  14. Height: 200px;
  15. Font-size: 12px;
  16. Background: #666;
  17. Border: 1px solid #000;
  18. Z-index: 10001;
  19. Display: none;
  20. Text-align: center;
  21. }
  22. </Style>
  23. <SCRIPT type = "text/ecmascript">
  24. $ (Document). Ready (function (){
  25. $ ("Input"). Click (function (){
  26. $ ("Body"). Dialog ();
  27. })
  28. })
  29. </SCRIPT>
  30. </Head>
  31. <Body>
  32. <Div>
  33. <Input type = "button" value = "Hi plugin"/>
  34. </Div>
  35. </Body>
  36. </Html>

Jquery. Dialog. JS:

  1. // JScript File
  2. $. FN. Dialog = function (){
  3. This. maskdiv = function () // customize a function
  4. {
  5. VaR WND = $ (window), Doc = $ (document );
  6. If (WND. Height ()> Doc. Height () {// when the height is less than one screen
  7. Wheight = WND. Height ();
  8. } Else {// when the height is greater than one screen
  9. Wheight = Doc. Height ();
  10. }
  11. // Create a mask background
  12. $ ("Body"). append ("<Div id = maskid> </div> ");
  13. $ ("Body"). Find ("# maskid"). Width (WND. Width (). Height (wheight)
  14. . CSS ({position: "absolute", top: "0px", left: "0px", Background: "# CCC", filter: "alpha (opacity = 90 );", opacity: "0.3", zindex: "10000 "});
  15. }
  16. This. sposition = function (OBJ) // customize a function with Parameters
  17. {
  18. VaR mydiv_w = parseint (obj. Width ());
  19. VaR mydiv_h = parseint (obj. Height ());
  20. VaR width = parseint ($ (document). Width ());
  21. VaR Height = parseint ($ (window). Height ());
  22. VaR left = parseint ($ (document). scrollleft ());
  23. VaR Top = parseint ($ (document). scrolltop ());
  24. VaR div_topposition = Top + (height/2)-(mydiv_h/2); // calculate the top margin
  25. VaR div_leftposition = left + (width/2)-(mydiv_w/2); // calculate the left margin
  26. Return array (div_topposition, div_leftposition );
  27. }
  28. This. maskdiv ();
  29. $ ("Body "). append ("<Div id = divdialog style = 'display: none'> <ul> <li> prompt </LI> </ul> </div> ");
  30. VaR OBJ = $ ("body"). Find ("# divdialog ");
  31. OBJ. Width ("200px"). Height ("200px ");
  32. Post = This. sposition (OBJ );
  33. Obj.css ({position: "absolute", top: Post [0] + "PX", left: Post [1] + "PX", Background: "# ffcc66", zindex: "10001 "}). show ("slow ");
  34. Return this;
  35. }

End

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.