Jquery tutorial (13) jquery lightbox (plug-in)

Source: Internet
Author: User

The first version of "thickbox" transplanted by Cody Lindley made me feel the charm of jquery for the first time. Later, he made some code upgrades to fix cross-browser compatibility issues.

Notes

$ (Document). Ready replaces the tb_init () function by appending an onclick event to each link containing the object name "thickbox.

Function tb_init(){$("A. thickbox").Click(Function(){VaR T =This.Title|This.Innerhtml|This.HrefExtra Tb _ show(T,This.Href)Bytes ;This.Blur()Bytes ;Return FalseBytes ;})Bytes ;

When these links are clicked, The tb_show () function is executed.

$(  "Body"  ) . Append  (  ""  ) Billing $ (  "# Tb_overlay"  ) . Click  ( Tb_remove ) Billing $ ( Window ) . Resize  ( Tb_position ) Billing $ ( Window) . Scroll  ( Tb_position ) Billing $ (  "# Tb_overlay"  ) . Show  (  ) Billing $ (  "Body"  ) . Append  (  ""  ) Bytes ;

As you can see, two DIV elements are added before the document body element. In other words, the two DIV elements will be added to the htmlCodeBefore closing the element.

The covered Div uses a specific CSS file containing an opaque appearance to specify the performance. The tb_window code is used to place an image in the page through Ahah or add another page. $ (Window). Resize and $ (window). Scroll tell jquery to execute the tb_position function when you resize the window or drag the page to flip the page. This is a means to ensure that thickbox is always in the center of the window.

Then, Cody queries the URL suffix.

VaR urlstring = /.JPG|.JPEG|.PNG|.GIF|.Html|.Htm|.PHP|.CFM|.ASP|.Aspx|.JSP|.JST|.RB|.Txt/G required var urltype = URL.Match(Urlstring)Bytes ;If(Urltype ='.Jpg'| Urltype ='.Jpeg'| Urltype ='.Png'| Urltype ='.Gif'){// Code to show images

If this is an image file, the jquery append function will add HTML code to the appropriate location.

$("# Tb_window").Append(""+"" Close"+ Caption +")Billing $("# Tb_closewindowbutton").Click(Tb_remove)Bytes ;

In addition, the remote file will be imported using jquery's load () function.

 
$("# Tb_ajaxcontent").Load(URL, Function(){...................

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.