IE7 上的边距问题与绝对位置上的 jQuery 悬停效果

发布于 2024-09-09 01:33:41 字数 1285 浏览 1 评论 0原文

仅在 IE7 上悬停图像时,在 .nav li p 上设置绝对位置会产生额外的边距,但如果没有绝对位置,图像会闪烁。

除了绝对定位还有其他选择吗?

这就是我所拥有的:

$('ul.nav li').hover(function() {
  $(this).prepend('<p></p>')
         .find('p')
         .fadeIn('fast');
}, function() {
  $(this).find('p')
         .fadeOut('fast', function() {
            $(this).remove()
         });
});

CSS:

.nav li{
    width:360px;
}
.nav li p {
    width:360px;
    margin: 0;
    padding:0;
    position: absolute;
    display:none;
}
li#stylea {height:138px;background: url(images/1.jpg) 0 -474px no-repeat}
li#stylea p {height:138px;background: url(images/1.jpg) 0 bottom no-repeat;}
li#styleb { height:149px; background: url(images/1.jpg) 0 -176px no-repeat}
li#styleb p {height:149px;background: url(images/1.jpg) 0 -325px no-repeat;}

HTML:

<div>
   <ul class="nav">
      <li id="stylec"></li>
      <li id="styleb"></li>   
      <li id="stylea"></li>   
   </ul>
   <ul class="nav">
      <li id="styled"></li>   
      <li id="stylee"></li>   
      <li id="stylef"></li>                       
   </ul>
</div>

Having the absolute position on .nav li p creates extra margin when hovering an image only on IE7, but without the absolute position, images flicker.

Is there another option than the absolute positioning?

This is what I have:

$('ul.nav li').hover(function() {
  $(this).prepend('<p></p>')
         .find('p')
         .fadeIn('fast');
}, function() {
  $(this).find('p')
         .fadeOut('fast', function() {
            $(this).remove()
         });
});

CSS:

.nav li{
    width:360px;
}
.nav li p {
    width:360px;
    margin: 0;
    padding:0;
    position: absolute;
    display:none;
}
li#stylea {height:138px;background: url(images/1.jpg) 0 -474px no-repeat}
li#stylea p {height:138px;background: url(images/1.jpg) 0 bottom no-repeat;}
li#styleb { height:149px; background: url(images/1.jpg) 0 -176px no-repeat}
li#styleb p {height:149px;background: url(images/1.jpg) 0 -325px no-repeat;}

HTML:

<div>
   <ul class="nav">
      <li id="stylec"></li>
      <li id="styleb"></li>   
      <li id="stylea"></li>   
   </ul>
   <ul class="nav">
      <li id="styled"></li>   
      <li id="stylee"></li>   
      <li id="stylef"></li>                       
   </ul>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

—━☆沉默づ 2024-09-16 01:33:41

我要尝试的第一件事总是将 Zoom:1 添加到有问题的元素中。有时是父母..有时是孩子。 Zoom: 1 恰好让 IE7 处于一致状态。

你会惊讶地发现这种方法有多少次有效。

my first thing to try is always adding zoom:1 to the element(s) in question. sometimes the parent.. sometimes the child. zoom: 1 happens to put IE7 in line alot.

you'd be surprised how many times that works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文