jQuery SlideDown / SlideUp 在 IE7 中不起作用
所以我使用一个非常基本的 jQuery .slideDown,它在 FF、Safari 和 Chrome 中运行良好。在 IE7 中根本不起作用。这是脚本:
//Top Mailing List Drop down animation
$(document).ready(function() {
$('div#top_mailing_hidden').hide();
// Expand Panel
$("input#top_mailing").focus(function(){
$("div#top_mailing_hidden").slideDown("slow");
});
// Collapse Panel
$("input#top_mailing").blur(function(){
$("div#top_mailing_hidden").slideUp("slow");
});
});
我已经研究了几个小时,发现了一些与向上/向下滑动相关的错误,导致它在 IE7 中用于 postion:fixed 元素的后代时失败。这个动画发生在一个位置:固定的导航栏内,但是,我尝试用位置:相对包装内部元素,但无济于事,我在 IE 中仍然什么也得不到。另外,请注意,nav 元素被 jQuery 隐藏,该功能甚至在 IE7 中也能工作,但是,向上/向下滑动则不然。
这是相关的CSS:
/* --------------Top Dropdown Mailing List------------------- */
#top_nav div#top_mailing{
float: right;
width: 351px;
padding: 0 10px 10px 5px;
background: url(images/top_mailing_bg.png) bottom center no-repeat;
position: absolute;
top: 0;
right: 0;
color: #fff;
text-shadow:0 -1px 0px #222;
}
#top_mailing #top_mailing_hidden{
font-size: .7em;
text-align: center;
position: relative;
height: 30px;
zoom: 1;
}
#top_mailing #top_mailing_hidden div{
}
#top_mailing #top_mailing_hidden a{
color: #acffc0;
font-weight: bold;
}
#top_mailing #top_mailing_visible{
height: 30px;
font-weight: bold;
font-size: .9em;
padding-top: 5px;
}
So I'm using a very basic jQuery .slideDown which is working great in FF, Safari, and Chrome. Won't work at all in IE7. here is the script:
//Top Mailing List Drop down animation
$(document).ready(function() {
$('div#top_mailing_hidden').hide();
// Expand Panel
$("input#top_mailing").focus(function(){
$("div#top_mailing_hidden").slideDown("slow");
});
// Collapse Panel
$("input#top_mailing").blur(function(){
$("div#top_mailing_hidden").slideUp("slow");
});
});
I've been researching for hours and found something about a bug relating to slideup/down that causes it to fail in IE7 when being used on descendants of postion:fixed elements. This animation is happening within a position:fixed navbar, however, I've tried wrapping the inner elements with position:relative but to no avail, I still get nothing in IE. Also, notice that the nav element is being hidden with jQuery, that function is working even in IE7, however, the slideup/down are not.
Here is the related CSS:
/* --------------Top Dropdown Mailing List------------------- */
#top_nav div#top_mailing{
float: right;
width: 351px;
padding: 0 10px 10px 5px;
background: url(images/top_mailing_bg.png) bottom center no-repeat;
position: absolute;
top: 0;
right: 0;
color: #fff;
text-shadow:0 -1px 0px #222;
}
#top_mailing #top_mailing_hidden{
font-size: .7em;
text-align: center;
position: relative;
height: 30px;
zoom: 1;
}
#top_mailing #top_mailing_hidden div{
}
#top_mailing #top_mailing_hidden a{
color: #acffc0;
font-weight: bold;
}
#top_mailing #top_mailing_visible{
height: 30px;
font-weight: bold;
font-size: .9em;
padding-top: 5px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery 的
slideUp()
、slideDown()
和slideToggle()
不适用于position:relative
IE7 中的 > 元素。一些滑动问题可以通过添加
到滑动容器和/或元素来解决。
我们不得不恢复使用 ;用于布局解决一些滑动问题。
jQuery's
slideUp()
,slideDown()
andslideToggle()
don't work withposition:relative
elements in IE7.Some slide issues can be resolved by adding
To the sliding container and/or elements.
We had to revert to use <table> for layout to solve some of the sliding issues.
在我的示例中出现此行为的原因是 IE 无法识别我用来触发 .slideUp/Down 的 .focus。我在此处找到了一个很好的答案来解释问题,但是这允许您在焦点上添加 CSS 类,但我需要在 .focus 上使用 SlideUp/Down 为单独的元素设置动画,因此 CSS 类对我的情况没有帮助,有人有想法吗?
知道了!我必须使用 mouseenter 而不是 focus,但这里是完整的脚本,其中包含魔鬼(又名 IE)的条件 mouseenter 事件:
The reason for this behavior in my example is that IE doesn't recognize .focus which I was using to trigger the .slideUp/Down. I've found a good answer explaining the problem here, however this allows you to add a CSS class on focus, but I need to animate a separate element with slideUp/Down on .focus so the CSS class doesn't help my situation, anyone have ideas?
Got it! I had to use mouseenter rather than focus, but here is the completed script with a conditional mouseenter event for the devil, a.k.a. IE: