jQuery暴强Lightbox之Thickbox:对于所有应用Lightbox的图片及链接等只要加上原先给定的样式,再在ready中初使化一下(当然这个在你引用的thickbox.js中已自动初使化)这个东西已经在使用中真的很方便,引入js文件与修改css文件后,只要给链接绑上一个属性,class=thickbox即可。 当然弹出的ThickBox的大小还是要自己定义的,我的意思是在ready中自己给处理掉,Jquery本身没有这样的例子,大家可以自己做。

吕的部落格唯女子与小人为难养也近之则不孙远之则怨

jQuery暴强Lightbox之Thickbox

对于所有应用Lightbox的图片及链接等只要加上原先给定的样式,再在ready中初使化一下(当然这个在你引用的thickbox.js中已自动初使化)这个东西已经在使用中真的很方便,引入js文件与修改CSS文件后,只要给链接绑上一个属性,class="thickbox"即可。
当然弹出的ThickBox的大小还是要自己定义的,我的意思是在ready中自己给处理掉,jquery本身没有这样的例子,大家可以自己做。
全文 演示

A few things to notice

$(document).ready kicks off the TB_init() function, which in turn attaches an onClick event to all links with the class name of “thickbox”.

function TB_init(){

$("a.thickbox").click(function(){

var t = this.title || this.innerHTML || this.href;

TB_show(t,this.href);

this.blur();

return false;

});

When a “thickbox” link is clicked, the TB_show() function fires.

$("body")
.append("<div id='TB_overlay'></div><div id='TB_window'></div>");
$("#TB_overlay").click(TB_remove);
$(window).resize(TB_position);
$(window).scroll(TB_position);

$("#TB_overlay").show();
$("body").append("<div id='TB_load'><div id='TB_loadContent'><img
src='images/circle_animation.gif' /></div></div>");

As you can see above, there are two divs that are appended to the document body. In other words, the two divs are added to the end of the html just before the closing body tag.

The overlay div is styled by CSS to have an opaque appearance. The TB_window is where the script will place an image or pull in another web page using AHAH.

$(window).resize and $(window).scroll tell jquery to fire off the TB_position function if the window is resized by the visitor or if the visitor scrolls down the page. This is how Thickbox is able to stay in the middle of the page when you scroll or resize the window.

Next, Cody searches the url passed to the Thickbox code to find the suffix.

var urlString = /.jpg|.jpeg|.png|.gif|.html|.htm|.php|.cfm|.asp|.aspx|.jsp|.jst|.rb|.txt/g;

var urlType = url.match(urlString);

if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif'){//code to show images

If it’s an image, then the jquery append function is used to add the html to the appropriate spot.

$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img
id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"'
alt='"+caption+"'/></a>"
+ "<div id='TB_caption'>"+caption+"</div><div
id='TB_closeWindow'><a href='#' id='TB_closeWindowButton'>close</a></div>");

$("#TB_closeWindowButton").click(TB_remove);

Otherwise, the remote file is pulled in using the jquery load() function.

$("#TB_ajaxContent").load(url, function(){

所属分类:技术手册标签:JQueryThickbox jQueryLightboxThickbo强之x 吕 @ 2006年11月7日8点46分 AM 编辑 jQuery暴强Lightbox之Thickbox阅读(7178) 评论(8)

相关文章

评论

  • july @ 2007-2-5 11:11:56 回复1#RE:jQuery暴强Lightbox之Thickbox

    能不能在Thickbox 的弹出框中再次使用Jquery?
    尝试了Firefox,成功,但在IE下不行,请指点一下
  • 吕 @ 2007-2-6 8:14:35 回复2#RE:jQuery暴强Lightbox之Thickbox

    个人还没有这样用过,而且我都是使用Thickbox的Iframe的,弹出的肯定是可以用的。Ajax载入的话,载入的部分如果有一些Jquery操作也应该重新初使化来绑定载入部分的事件。Jquery应该也是可以用的。(我没试过的……)
  • July @ 2007-2-6 8:53:30 回复3#RE:jQuery暴强Lightbox之Thickbox

    应该是可以,但问题是它在Firefox下可以,而IE下不行

    载入页面也引入了Thickbox

  • 吕 @ 2007-2-6 9:55:18 回复4#RE:jQuery暴强Lightbox之Thickbox

    测试(点击下载),IE,Firefox下均可以。不过二级窗口不是以根级为基础创建的。窗口不能穿越它的容器窗口。
  • July @ 2007-2-7 8:34:01 回复5#RE:jQuery暴强Lightbox之Thickbox

    test2.html在哪? 我要的就是在test2.html 中载入jQuery ,并运用jQuery

    P.S.:可详细讨论,在MSN上。

  • 吕 @ 2007-2-7 9:29:18 回复6#RE:jQuery暴强Lightbox之Thickbox

    我到现在不知道你用的是Iframe还是AJAX,如果是Iframe,原理上说都是可行的。因为其本身就可以看做一个独立的窗体
  • July @ 2007-2-8 20:27:10 回复7#RE:jQuery暴强Lightbox之Thickbox

    换了 不用Thickbox了 改成Graybox ,就没有这个问题了~ Graybox 用的是IFrame

    现在碰到一个问题,如下:
    <select id="selectlink">
        <option selected >Select a link to Edit</span></option>
    </select>
    for( i=0; i<count; i )
    {
         $("#selectlink").append("<OPTION value=1><SPAN class=style6>1</SPAN></OPTION>");
    }
    就是在给Select 动态加Option, 但加的缺少<OPTION value=1> ,这是什么问题呢?


  • 吕 @ 2007-2-11 9:27:41 回复8#RE:jQuery暴强Lightbox之Thickbox

    GrayBOx好像从tHICKBOX改过来的,Thickbox本身包含三种载入方式,Iframe,Ajax,InnerHTML,看你选择了.

    你留的js代码错好多地方,不知道是打错了,还是你的代码就是这样,FOR不但语法错了,而且这用FOR不知道你是想做什么.如果是代码出错,肯定是加不进去的了

注:部分评论不可见.
未开放评论

谷歌中jQuery暴强Lightbox之Thickbox相关文章

数据加载中,请稍候……