Categories: jQueryWeb前端

jquery下mouseenter、mouseleave在IE6中仍然闪烁的解决方案!

jquery下mouseenter的预期效果!

html代码:

<section>
<ul>
<li>
<a href=”#”><img src=”http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/1.jpg” width=”230″ height=”170″ alt=”海星水族箱”></a>
<a href=”#”>海星水族箱</a>
</li>
<li>
<a href=”#”><img src=”http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/2.jpg” width=”150″ height=”170″ alt=”过滤装置”></a>
<a href=”#”>过滤装置</a>
</li>
<li>
<a href=”#”><img src=”http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/3.jpg” width=”150″ height=”170″ alt=”潜水泵/机头”></a>
<a href=”#”>潜水泵/机头</a>
</li>
<li>
<a href=”#”><img src=”http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/4.jpg” width=”170″ height=”170″ alt=”照明装置”></a>
<a href=”#”>照明装置</a>
</li>
<li>
<a href=”#”><img src=”http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/5.jpg” width=”150″ height=”170″ alt=”加热棒”></a>
<a href=”#”>加热棒</a>
</li>
<li>
<a href=”#”><img src=”http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/6.jpg” width=”150″ height=”170″ alt=”气泵”></a>
<a href=”#”>气泵</a>
</li>
</ul>
</section>

js代码:

<script>
$(document).ready(function(){
$(“.product-category li:not(.hover)”).mouseenter(function(){
// $(this).addClass(“hover”);
/* 解决 IE 6 下闪烁的问题 */
$(this).css(“background”,”url(http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/hover-bg.png) center bottom no-repeat”);
$(this).find(“.category”).css({ background: “#303030”,color: “#FFF” });
}).mouseleave(function(){
// $(this).removeClass(“hover”);
$(this).css(“background”,”none”);
$(this).find(“.category”).css({ background: “none”,color: “#6C6C6C” });
});
});
</script>

 

css代码:

/* 水族产品类别 */

.product-category {
width: 1000px;
height: 216px;
float: left;
border-top: 1px solid #C9C9C9;
padding-top: 20px;
}
.product-category ul {
width: 1000px;
height: 216px;
float: left;
background: url(http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/bg.png) left 171px repeat-x;
overflow: hidden;
}
.product-category li {
display: block;
float: left;
width: 150px;
height: 216px;
text-align: center;
overflow: hidden;
}
.product-category .hover {
background: url(http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/hover-bg.png) center bottom no-repeat;
}
.product-category img {
display: block;
width: 150px;
height: 170px;
}
.product-category .category {
display: inline-block;
margin-bottom: 15px;
height: 25px;
line-height: 25px;
text-align: center;
color: #6C6C6C;
font-family: “Microsoft Yahei”;
font-size: 14px;
padding-left: 5px;
padding-right: 5px;
margin-top: 6px;
}
.product-category a.category:hover,
.product-category .hover .category {
background-color: #303030;
color: #FFF;
}
.product-category .tank {
width: 230px;
}
.product-category .tank img {
width: 230px;
}
.product-category .lighting {
width: 170px;
}
.product-category .lighting img {
width: 170px;
}

 

解决方案为:

原始js代码:

<script>
$(document).ready(function(){
$(“.product-category li:not(.hover)”).mouseenter(function(){
$(this).addClass(“hover”);
}).mouseleave(function(){
$(this).removeClass(“hover”);
});
});
</script>

修改为:

<script>
$(document).ready(function(){
$(“.product-category li:not(.hover)”).mouseenter(function(){
// $(this).addClass(“hover”);
/* 解决 IE 6 下闪烁的问题 */
$(this).css(“background”,”url(http://www.lassaquarium.com/tpl/lassaquarium/images/product/product-category/hover-bg.png) center bottom no-repeat”);
$(this).find(“.category”).css({ background: “#303030”,color: “#FFF” });
}).mouseleave(function(){
// $(this).removeClass(“hover”);
$(this).css(“background”,”none”);
$(this).find(“.category”).css({ background: “none”,color: “#6C6C6C” });
});
});
</script>

 

由于在IE6下操作类名添加的时候出现闪烁的问题,几经周折仍然无法解决,最好只好直接操作样式效果了,终于未闪烁了的!

 

永夜