最近一个朋友做个menu必须要覆盖select,没办法只有用下面这个方法。

转载自: http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx

It was about 1 year ago that Coalesys released the first WebMenu 2.0 beta.  At that time we began demonstrating a technique for overlaying windowed controls in Internet Explorer.

In case you don't already know, windowed controls in IE will always cover DHTML layers.  That means if you have a DIV that pops up or floats on the page and it intersects with a windowed control (such as the common SELECT box), the windowed control will obscure the DIV, no matter what zIndex you have set for each element.  More information is available in this Microsoft KB article .

The initial solution adopted by most developers who cared about such things (including ourselves) was to dynamically hide windowed controls when it was necessary to display the DIV over them.  Far from being a perfect solution, it was better than the alternative of doing nothing at all.

It did have one very frustrating aspect.  People who evaluated WebMenu didn't understand why their select boxes would disappear.  And we are talking much more than just ASP.NET developers, as we produce WebMenu for ASP , as well as general web development .  It seemed like every day we received a support question, "I found a bug in WebMenu. The select boxes are disappearing".  And although we did provide the ability to turn the feature off, nobody really bothered once they understood the nature of the issue.

Then, as luck would have it, a developer called who wanted to use our product for it's broad set of features, but who absolutely needed to have the menu appear over some windowed objects.  What was unique about his call was that he had the idea for a solution and shared it with us.  While we didn't use the full scope of his idea, we were able to take from it what we needed to cover windowed controls in IE 5.5.  So, enough yacking.  You probably surfed here to read about the solution.  And here it is:

IFRAME

The IFRAME control has a unique nature in IE 5.5.  It can exist in both the zIndex of windowed controls and the zIndex of regular HTML elements.  Simply put, you can shim an IFRAME under your DIV. The IFRAME will block out the windowed control.

Set up your IFRAME :

<IFRAME style="DISPLAY: none; LEFT: 0px; POSITION: absolute; TOP: 0px" src="javascript:false;" frameBorder="0" scrolling="no"></IFRAME>

The src attribute is set with a useless JavaScript statement so that the IFRAME does not try to load a page (which you won't notice it doing, but it will be the cause for tripping the "Unsecured Items" message if you use it on a HTTPS page).

You can code your IFRAME as a static element on the page, or if you are going to be using more than one of them you may want to dynamically create them as required.  The insertAdjacentHTML() method is good for that.

Now, all that is needed is to size the IFRAME according to the dimensions of your DIV, position it, place it one layer beneath the DIV in the zIndex order and make it "visible".  The IFRAME's style object will allow you to do these tasks:

iframe .style.top
iframe .style.left
iframe .style.width
iframe .style.height
iframe .style.zIndex
iframe .style.display

What about transparency?

If the DIV has transparent areas, you'll want those areas to punch through the IFRAME to the page background.  There are two ways you can make an IFRAME transparent.  The one that works for this situation is to set the style object's filter property:

iframe .style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';

This in effect makes the entire IFRAME transparent, but it will still block out the windowed controls .  The other technique, which uses the IFRAME element's ALLOWTRANSPARENCY attribute, actually pertains to making the interior page background of the IFRAME transparent, so that any content inside the IFRAME can have transparency.  However, this mode changes the nature of the IFRAME and it no longer serves our purpose for blocking out windowed controls.

What about IE versions prior to 5.5?

The IFRAME's unique nature surfaced only in IE 5.5.  Prior to this, IFRAMEs where straight windowed controls themselves.  That means they could get above other windowed controls, but no HTML element (like the DIV) could be seen above them.  There is a solution, but it involves a lot of effort to get working.  You can dynamically write the content of your DIV into the IFRAME itself, get it sized appropriately based on the dimensions of the original DIV, and then just move it around as your absolutely positioned element.  There are a couple of caveats:

1.  The IFRAME, like any frame,  has it's own JavaScript environment.  If you want DHTML actions in the IFRAME to integrate with the JavaScript functions in your main page, you will have to bridge the gap between the two JavaScript environments.

2.  Mouse events, such as OnMouseOut and OnMouseOver, can be called out of logical order when the mouse moves between frames in IE 4 and 5.  This problem is compounded when you are using timers and need to precisely control their execution and cancellation via mouse events.

Our original WebMenu 2.0 beta used this technique successfully for IE 4 and 5, but in looking forward to adding new features to the product, we could see that this solution "over-worked the plumbing" to a great extent.  The "shim" technique compatible only with IE 5.5 had zero architectural impact and was chosen for this reason.  You can still hide windowed elements in earlier browsers as an acceptable solution.

还有一篇中文的,在google里很多,我也不知道哪个是原作,如果是您,请通知我我会立即加上链接:)

下拉框,即html的SELECT元素,.net设计时的DropDownList,是html中的windowed element,尤其ie6之后,几乎是唯一的windowed element(还有popup等少量极少用的的)。

普 通的元素,textbox, div, table……这些,属于windowless element,它们之间互相遮盖的情况由z-index决定,在它们之上,是SELECT这些windowed element。所以一般情况下div、table等不能遮盖select。

这个问题广泛存在于各种弹出式控件的使用之中,比如日历控件等。

如 果要显示div,以前的做法是,动态的,在显示的时候,让div区域的select不可见,div消失的时候,再恢复这些select元素。这种做法比较 奇怪,因为它严格上并不是“遮盖”了select,而是,让她整个消失了,如果calendar弹出元素只是应该遮盖select元素的一部分,但 select却整个不见,用户也许会觉得奇怪;做起来也麻烦,要用js逐一判断各select的位置。

ie5.5之后,有一个新的小技巧,称之为“iframe shim”(iframe加塞:p),可以真正的“遮盖”select元素。

它 利用了一种特殊的元素:iframe。在ie5.5之前,iframe也是windowed element,但从5.5开始,iframe就是普通的windowless element了,可是,虽然是windowless element,iframe却可以盖住select。这种做法的原理就是:放一个iframe与你要显示的东西(比如说一个div)同样大小、位置,并 设置z-index使得iframe在此DIV之下;这样,iframe遮盖了select,同时,iframe又在要显示的div的下面,div就露出 来了。

限制:仅适用于ie5.5及以后版本。

参考文章链接:
http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx

示例程序代码:
//html.select.hack.iframe shim.htm
<html>
<head>
<script>
function DivSetVisible(state)
{
var DivRef = document.getElementById('PopupDiv');
var IfrRef = document.getElementById('DivShim');
if(state)
{
DivRef.style.display = "block";
IfrRef.style.width = DivRef.offsetWidth;
IfrRef.style.height = DivRef.offsetHeight;
IfrRef.style.top = DivRef.style.top;
IfrRef.style.left = DivRef.style.left;
IfrRef.style.zIndex = DivRef.style.zIndex - 1;
IfrRef.style.display = "block";
}
else
{
DivRef.style.display = "none";
IfrRef.style.display = "none";
}
}
</script>
</head>
<body background="http://www.orkut.com/img/i_blau2.gif">
<form>
<select>
<option>A Select Box is Born ....</option>
</select>
</form>
<div
id="PopupDiv"
style="position:absolute;font:italic normal bolder 12pt Arial; top:25px; left:50px; padding:4px; display:none; color:#ffff00; z-index:100">
.... and a DIV can cover it up<br>through the help of an IFRAME.
</div>
<iframe
id="DivShim"
src="javascript:false;"
scrolling="no"
frameborder="0"
style="position:absolute; top:0px; left:0px; display:none;filter=progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);">
</iframe>
<br>
<br>
<a href="#" οnclick="DivSetVisible(true)">Click to show DIV.</a>
<br>
<br>
<a href="#" οnclick="DivSetVisible(false)">Click to hide DIV.</a>
</body>
</html>

How to cover an IE windowed control (Select Box, ActiveX Object, etc.) with a DHTML layer.相关推荐

  1. Magento: 左栏筛选条件 Select Box / Button / Dropdown List on Layered Navigation

    1. 下拉框 Select Box You have plain text and link to those text in Magento Layered Navigation section. ...

  2. A Complete ActiveX Web Control Tutorial

    VC++开发ActiveX 控件 转载:http://www.codeproject.com/KB/COM/CompleteActiveX.aspx 效果图如下: Introduction Activ ...

  3. 一次控制文件control file sequential read 等待性能案例分析

    记录关于control file的一个事件, 此事件只是通知类event,和db file sequential read类似为数据库的I/O类操作,但wait class不是USER I/O,而是S ...

  4. html 下拉组件被下面的组件挡住,div被select下拉框挡住了--5种解决方法

    在IE中,select属于window类型控件,它会"挡住"所有非window类型控件 可以这么理解,div这样的组件是在浏览器客户区使用代码"渲染"的, 他们 ...

  5. html 下拉组件被下面的组件挡住,select挡住div的5种解决方法

    在IE中,select属于window类型控件,它会"挡住"所有非window类型控件 可以这么理解,div这样的组件是在浏览器客户区使用代码"渲染"的, 他们 ...

  6. html select滚动轴,javascript - html select scroll bar - Stack Overflow

    how do you add a scroll bar to the html select box? is there any javascript library that emulate thi ...

  7. jQuery美化select下拉框

    想必很多朋友都知道,<select />.<input type="file" />默认是不能通过样式美化的.前几天在做一个项目的时候恰巧要用到一个sele ...

  8. 为什么Control类提供了Invoke和BeginInvoke机制

    在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate,至于委托的本质请参考我的另一随笔:对.net事件的看法. 一.为什么Control类提供了Invoke和Begin ...

  9. 委托的Invoke 和 BeginInvoke 与Control的Invoke和BeginInvoke(转-因为写得很好)

    原文地址:http://www.cnblogs.com/worldreason/archive/2008/06/09/1216127.html Invoke and BeginInvoke Invok ...

  10. layui select下拉框改变之 change 监听事件

     在layui中使用 jquery 触发select 的 change事件无效 使用layui.use监听select事件  <select lay-filter="demo" ...

最新文章

  1. Jquery之dom操作
  2. gitlab开启https加密 and 全站https
  3. anki 新的卡片类型_梁宝川:这一类型Anki卡片,你做了吗?
  4. ip netns 命令使用
  5. 统一代码风格工具 editorConfig
  6. mysql的一些初步使用!mysqlcheck mysqladmin 建立删除修改表,库,等
  7. jQuery获取iframe的document对象的方法
  8. 牛客网_PAT乙级1004_福尔摩斯的约会 (20)
  9. python怎么输出一个数组_python中实现将多个print输出合成一个数组
  10. IOS pushViewController如何去隐藏tabbar
  11. vba传值调用_Access VBA如何使用Shell命令以及如何传递参数
  12. 微软宣布明年停止支持已推出25年的IE浏览器
  13. 游戏 TRAP(SNRS)AlphaBeta版本
  14. spring boot 和spring mvc区别
  15. idesk卸载教程_iDesk助手使用帮助
  16. centos tomcat部署
  17. Python 缩写月份单词
  18. vue跑项目npm run dev 时报错cannot GET /;node-sass安装失败问题
  19. GBASE 8s中loadunload
  20. RabbitMQ 安装与web后台管理界面开启

热门文章

  1. PHP微信公众号开发
  2. Python的scrapy之爬取6毛小说网
  3. 麒麟桌面系统时间相关命令介绍
  4. The requested URL returned error: 403
  5. OSChina 周二乱弹 —— 代码中的坑是怎么出现的?
  6. 基于MAX2671设计的400Mhz混频器
  7. 如何进入Github【亲测有效】
  8. FAT32学习笔记(五)——fat相关工具
  9. RAM的 Parity 与 ECC
  10. win10连不上网,几种尝试