没有不值得去解决的问题,也没有不值得去学习的技术!

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

jquery下mouseenter的预期效果!

作者:

,
jquery下mouseenter的预期效果!
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下操作类名添加的时候出现闪烁的问题,几经周折仍然无法解决,最好只好直接操作样式效果了,终于未闪烁了的!

 

需要长期技术维护或远程问题排查?

我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。

如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:

  • ✅ PHP / Laravel / Yii2 老项目无人维护
  • ✅ Go / Gin 后端接口需要排查或优化
  • ✅ WordPress 网站访问慢、报错或插件冲突
  • ✅ Nginx / MySQL / Redis / Linux 服务器异常
  • ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
  • ✅ 需要长期远程技术支持或兼职维护

更多介绍请查看:关于我 & 合作

微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理