zoukankan      html  css  js  c++  java
  • Jquery插件Thickbox的使用总结及自定义设置

    ThickBox运行需要的文件

    官方下载:

    Download thickbox.js or thickbox-compressed.js, ThickBox.css, and the loading graphic (loadingAnimation.gif) to your local machine (or cut and paste the code from the tabs). Along with these three files, a copy of the jQuery JavaScript library is needed. For this site, and ThickBox, I am using the compressed version of jQuery.

    首先在 HTML 文件的 head中导入jquery.js 和thickbox.js文件,导入 thickbox.css 文件;并且jquery.js 文件放在前面:

    <script src="../Scripts/jquery-latest.pack.js" mce_src="Scripts/jquery-latest.pack.js" type="text/javascript"></script>  
        <script src="../Scripts/thickbox.js" mce_src="Scripts/thickbox.js" type="text/javascript"></script>  
    <link href="../Styles/thickbox.css" mce_href="Styles/thickbox.css" rel="stylesheet" type="text/css" />  

    最后你只要给元素添加 class=”thickbox” 属性就可以开始用 thickbox

    实现了一张图片的弹出展示功能:

    <a href="”bg.jpg”" mce_href="”bg.jpg”" class=”thickbox” ><img src="”bg.jpg”" mce_src="”bg.jpg”" alt=”图片”/></a>  
    //只需要指定图片的class为thickbox
    弹出框使用方法:
    <a href="Default.aspx?keepThis=true&TB_iframe=true&height=400&width=500" title="主页" class="thickbox" </a>  
    <input onclick="<web.path:path/>/bannedUserList!unBannedUserList?height=400&width=800&inlineId=myOnPageContent" title="弹出层" class="thickbox" type="button" value="Ban Another" />  
    //内嵌内容  
    <input alt="#TB_inline?height=300&width=400&inlineId=myOnPageContent" title="标题" class="thickbox" type="button" value="Show" />    
    <a href="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" class="thickbox">显示隐藏内容a>  
    //遮罩层  
    URL后面加?KeepThis=true&TB_iframe=true&height=400&width=600  
    参数字符串中加 modal=true  
    ?KeepThis=true&TB_iframe=true&height=400&width=600&modal=true  
    这样当关闭ThickBox时会调用ThickBox iframe (self.parent.tb_remove())内部的一个tb_remove()函数  
    所有其他参数字符都必须在TB_iframe 参数之前。URL中所有"TB" 之后的将被移除。  
    <a href="index.html?keepThis=true&TB_iframe=true&height=250&width=400" title="标题" class="thickbox">打开一个页面</a>    
    <a href="index.html?keepThis=true&TB_iframe=true&height=300&width=500" title="标题" class="thickbox">打开一个页面</a>  
    <a href="index.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="标题" class="thickbox">打开一个页面</a>  

    自定义设置:

    1、弹出窗口(div)右上角的关闭按钮为显示为"close or esc key",而不是中文的; 如果想把它变成[X]或"关闭"应该怎么来办呢?

    将thickbox.js文件打开,查找关键字"or esc key",将其删除,并将前面的close更改为[X]或"关闭",然后把文件另存为UTF-8格式,如果不保存为UTF-8的话,将会出现乱码。
    2、thickbox 弹出层的遮住层透明度修改

    打开thickbox.css查找.TB_overlayBG 进行更改

    .TB_overlayBG {  
     background-color:#000;  
     filter:alpha(opacity=75);  
     -moz-opacity: 0.75;  
     opacity: 0.75;  
    }

    3、关闭层:如果我们需要自己添加一个关闭按钮或者图片可以使用:

    onclick="self.parent.tb_remove();"  

    4、关闭层刷新父页面,修改关闭方法 :

    function tb_remove() {
     	$("#TB_imageOff").unbind("click");
    	$("#TB_closeWindowButton").unbind("click");
    	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
    	$("#TB_load").remove();
    	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
    		$("body","html").css({height: "auto",  "auto"});
    		$("html").css("overflow","");
    	}
    	document.onkeydown = "";
    	document.onkeyup = "";
    	//刷新父页面,未指定
    	window.location.reload();
    	return false;
    }

    5、thickbox插件默认情况是点击灰色的遮罩层就会关闭取消

    把两个$("#TB_overlay").click(tb_remove);去掉就可以取消掉

    6、updatepanel回发后thickbox失效的解决方法

    只需把以下代码粘贴至页面中就OK了。
    
    <script type="text/javascript" language="javascript">
    function pageLoad()
    {
        var isAsyncPostback = Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack();
        if (isAsyncPostback) 
        {
            tb_init('a.thickbox, area.thickbox, input.thickbox');
        }
    }
    </script>
  • 相关阅读:
    注册InstallShield
    java学习——异常处理
    IntellJ IDEA下写JUnit
    【转】光盘和U盘安装win7和ubuntu14.04全步骤
    上汽笔试题
    小白面试
    mysql
    HOWTO: Setup XCode 6.1 to work with OpenCV3 libraries
    [转]在MacOS和iOS系统中使用OpenCV
    [转]在 Mac OS X 终端里使用 Solarized 配色方案
  • 原文地址:https://www.cnblogs.com/dupeng0811/p/1981270.html
Copyright © 2011-2022 走看看