【问题标题】:jQuery - Compatibility Problem with Internet Explorer 7?jQuery - Internet Explorer 7 的兼容性问题?
【发布时间】:2009-02-08 21:18:58
【问题描述】:

我有这段代码,当鼠标悬停在图像上时,它会动态地将 Div 向上滑动。它在 Firefox 和 Google Chrome 中完美运行,但在 Internet Explorer 7 中,一切运行非常缓慢,什么也没有发生。

jquery 代码是这样的:

jQuery.fn.masque = function(class) {

$(this).hover(function(){
$(this).find(class).stop().animate({height:'100px',opacity: '0.9'},400);
},function () { 
$(this).find(class).stop().animate({height:'0',opacity: '0'}, 300);
});
}
$(document).ready(function(){$('.thumb').masque('.masque');});

HTML:

<div class="thumb bg25">
    <a href="#"><img src="img/image.jpg" alt="Something" /></a>
        <div class="masque">
            <h3 class="someclass"><a href="#" >Some text here</a></h3>
            <p class="someclass">Some text here</p>
            <p class="someclass">Some text here</p>
        </div>
</div>

这是 CSS:

.thumb {float:left; margin:0 14px 14px 0; width:126px; height:186px; padding:10px; position:relative;}

.masque{position:absolute; background:#212326; width:118px; bottom:10px; height:0; padding:4px; display:none;}

我是在本地机器上运行它,而不是在服务器上。

.. 所以我认为我做错了什么,也许有一种有效的方法可以实现这种效果。 谢谢!!!

【问题讨论】:

  • 如果您需要这里是 CSS:.thumb {float:left;边距:0 14px 14px 0;宽度:126px;高度:186px;填充:10px;位置:相对;} .masque {位置:绝对;背景:#212326;宽度:118px;底部:10px;高度:0;填充:4px;显示:无;}
  • @Jonathan - 最好编辑您的问题并在代码块中添加 CSS :)

标签: javascript jquery internet-explorer cross-browser


【解决方案1】:

你试过关闭 stop() 吗?我完全在黑暗中拍摄,但我认为 IE7 可能会以不同的方式排队呼叫。我现在就测试一下。

更新

在测试它之后,由于名为 class 的变量,我在 IE7 中遇到了一些奇怪的错误。那一定是某种关键字。试试这个。

jQuery.fn.masque = function(classSelector) {
        $(this).hover(function(){
                $(this).find(classSelector).stop().animate({height:'100px',opacity: '0.9'},400);
        },function () {
            $(this).find(classSelector).stop().animate({height:'0',opacity: '0'}, 300);
        });
};

更新

您尝试过使用 slideUp 和 slideDown 吗?

jQuery.fn.masque = function(classSelector) {
    $(this).hover(function(){
        $(this).find(classSelector).slideDown();
    },function () {
        $(this).find(classSelector).slideUp();
    });
};

【讨论】:

  • 谢谢!如果您需要这里是 CSS: .thumb {float:left;边距:0 14px 14px 0;宽度:126px;高度:186px;填充:10px;位置:相对;} .masque {位置:绝对;背景:#212326;宽度:118px;底部:10px;高度:0;填充:4px;显示:无;}
  • 顺便说一句,将来不要将 css 添加到评论中,而是将其添加到您的帖子中,但请注意在评论中添加。
  • 谢谢,现在我看到 IE7 中的 div 向上滑动,但它仍然很慢,定位不好而且有问题...也许有更好的编码方法?
  • 顺便说一句,这是我从 www.foliostars.net 复制的代码并对其进行了修改...所以我不太了解 jQuery...
  • 你的图片尺寸是多少。
猜你喜欢
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-11
  • 2014-02-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-31
相关资源
最近更新 更多