IE下元素空白区域(该元素在上img在下)与图片重叠无法触发鼠标事件

  发布时间:2013-01-18 16:49:00   作者:佚名   我要评论
IE 下与元素重叠的区域为img(该元素在上img在下),且该元素无背景,则该区域无法触发鼠标事件,很是郁闷,与大家分享下,不知有没有更好的解决方法
IE 下与元素重叠的区域为 img(该元素在上img在下),且该元素无背景(background:none、transparent),无可见内容(如 display none,visibllity hidden,left:-9999px; ) ,则该区域无法触发鼠标事件

复制代码
代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>test</title>
<style>
.ad-gallery{
position: relative;
width: 400px;
height: 350px;
overflow: hidden;
}
.ad-gallery .ad-prev,.ad-gallery .ad-next{
position: relative;
display: inline-block;
*display: inline;
*zoom:1;
float: left;
width:200px;
height: 100%;
z-index:100;
background-image: url('about:blank'); /* IE ,与元素重叠的区域为 img(该元素在上img在下),且该元素无背景(background:none、transparent),无可见内容(如 display none,visibllity hidden,left:-9999px; ) ,则该区域无法触发鼠标事件 */
}
.ad-gallery .prevHandle ,.ad-gallery .nextHandle{
position:absolute;
left:0;
right: 0;
top: 0;
bottom: 0;
margin:auto;
*top:50%;
*left:50%;
*margin-left: -50px;
*margin-top: -75px;
width: 100px;
height: 150px;
line-height: 150px;
background: #313131;
font-size: 14px;
text-align: center;
color: #ddd;
background: #313131;
display: none;
/*visibility: hidden;*/
/*left:-9999px; */
}
.ad-gallery .ad-img{
position: absolute;
top:0;
left:0;
z-index: 0;
width: 100%;
height: 100%;
}
.ad-gallery .desc{
position: absolute;
left: 0px;
bottom: 0px;
margin:0;
width: 100%;
height: 50px;
line-height: 50px;
background: #313131;
color: #eee;
text-indent: 10px;
z-index: 99;
}
.opacity60{
*filter:alpha(opacity=60);/*IE6、7*/
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=60)"; /*IE8*/
opacity: 0.6;
}
</style>
</head>
<body>
<div id="gallery" class="ad-gallery">
<img class="ad-img" src="//img.jbzj.com/file_images/article/201301/2013118165025387.jpg" />
<div class="ad-prev"><div class="prevHandle opacity60">上一张</div></div>
<div class="ad-next"><div class="nextHandle opacity60">下一张</div></div>
<div class="desc opacity60">image description</div>
</div>
<!--test-->
<div style="position:relative;width:100px;height:111px;border:1px solid red;overflow:hidden;">
<img class="ad-img" width="100" height="50" src="http://images.cnblogs.com/cnblogs_com/ecalf/431722/o_7_4c135bd08efea.jpg" />
<div style="position:absolute;left:0;top:0;width:111px;height:100px;border:1px solid green;" onmouseover="alert(1);"></div>
</div>
<script>
var gallery = document.getElementById("gallery");
var elmInGallery = gallery.getElementsByTagName("*");
var mouseover = function(event){
event = event||window.event;
var target = (event.srcElement||event.target);
console.log('============= event log ===============');
console.log('1. ',this.className,' | ',target.className,' | ',target==this?'eventSrc':'eventTraval');
if((/ad-prev|ad-next/).test(this.className)){
console.log('2. ','handle active');
this.getElementsByTagName("div")[0].style.display = "block";
}
};
for(var i=0;i<elmInGallery.length;i++){
elmInGallery[i].onmouseover = mouseover;
}
</script>
</body>
</html>

相关文章

  • 浅谈原生页面兼容IE9问题的解决方案

    这篇文章主要介绍了浅谈原生页面兼容IE9问题的解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起
    2020-12-16
  • 新版chrome浏览器设置允许跨域的实现

    这篇文章主要介绍了新版chrome浏览器设置允许跨域的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起
    2020-11-30
  • css hack之\9和\0就可能对hack IE11\IE9\IE8无效

    每次设计一张网页或一个表单,都被各种浏览器的兼容问题伤透脑筋,尤其是IE家族。在做兼容性设计时,我们往往会使用各种浏览器能识别的独特语法进行hack,从而达到各种浏览
    2020-03-20
  • css区分ie8/ie9/ie10/ie11 chrome firefox的代码

    这篇文章主要介绍了css区分ie8/ie9/ie10/ie11 chrome firefox的代码,需要的朋友可以参考下
    2020-03-20
  • 解决CSS浏览器兼容性问题的4种方案

    这篇文章主要介绍了解决CSS浏览器兼容性问题的4种方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学
    2020-02-28
  • 常见的浏览器兼容性问题(小结)

    这篇文章主要介绍了常见的浏览器兼容性问题(小结),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学
    2020-02-20
  • border-radius IE8兼容处理的方法

    这篇文章主要介绍了border-radius IE8兼容处理的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学
    2020-02-12
  • 浅谈遇到的几个浏览器兼容性问题

    这篇文章主要介绍了浅谈遇到的几个浏览器兼容性问题,详细的介绍了几种我遇到的问题和解决方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-09-26
  • base64图片在各种浏览器的兼容性处理

    这篇文章主要介绍了base64图片在各种浏览器的兼容性处理的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-09-14
  • 对常见的css属性进行浏览器兼容性总结(推荐)

    这篇文章主要介绍了对常见的css属性进行浏览器兼容性总结(推荐)的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-07-20

最新评论