现在的位置: 首页 > 综合 > 正文

IE6下使用jquery.bgiframe.js插件解决下拉框覆盖浮动层、Dialog的问题

2013年07月27日 ⁄ 综合 ⁄ 共 1963字 ⁄ 字号 评论关闭

程序猿都知道,IE6的使用情况在天朝还是挺普遍的,特别是在爱写日记的领导群中更加喜欢,如果我们做的网页上有下拉框、Div浮动层、Dialog之类的,会看到下拉选框总是把浮动区块div覆盖划破,bgiframe 插件解决IE6 的这个bug。


首先去jquery 官方网下载 jquery.bgiframe.js ,然后在页面引入插件:

<script type="text/javascript" src="jquery.bgiframe.js"></script>

然后对浮动层或者Dialog进行设置

<script type="text/javascript"> 

       $(function() {     
           $('#DivLay').bgiframe();       //DivLay为浮动Div层的ID 
        });     

</SCRIPT>

//或者,如果你使用的是Jquery的Dialog,可以利用Dialog的属性达到这个目的。

 $(document).ready(function(){ 
   $('#dialog').dialog({    
      height:600,
      width: 900,
      bgiframe: true         //解决下拉框遮盖div的bug
  });
 });


有图有真相:现在Dialog已经在IE6中完全覆盖下拉框了

插件源码:保存为js文件即可

/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Version 2.1.3-pre
 */

(function($){

$.fn.bgiframe = ($.browser.msie && /msie 6.0/i.test(navigator.userAgent) ? function(s) {
    s = $.extend({
        top     : 'auto', // auto == .currentStyle.borderTopWidth
        left    : 'auto', // auto == .currentStyle.borderLeftWidth
        width   : 'auto', // auto == offsetWidth
        height  : 'auto', // auto == offsetHeight
        opacity : true,
        src     : 'javascript:false;'
    }, s);
    var html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
                   'style="display:block;position:absolute;z-index:-1;'+
                       (s.opacity !== false?'filter:Alpha(Opacity='0');':'')+
                       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+'px')':prop(s.top))+';'+
                       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+'px')':prop(s.left))+';'+
                       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+'px')':prop(s.width))+';'+
                       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+'px')':prop(s.height))+';'+
                '"/>';
    return this.each(function() {
        if ( $(this).children('iframe.bgiframe').length === 0 )
            this.insertBefore( document.createElement(html), this.firstChild );
    });
} : function() { return this; });

// old alias
$.fn.bgIframe = $.fn.bgiframe;

function prop(n) {
    return n && n.constructor === Number ? n + 'px' : n;
}

})(jQuery);

或者到这里下载 jquery.bgiframe.js 文件 :  http://115.com/file/e771jb18#jquery.bgiframe.js

抱歉!评论已关闭.