IE中的jQuery fadeIn + fadeOut?

时间:2009-12-21 17:07:46

标签: jquery fade fadein

我在使用jadef和fadeOut jQuery的效果在IE(6 + 7 + 8)中正常工作时遇到问题。该脚本在FF和safari中运行良好(褪色很好),但在IE中它只是显示/隐藏 - 根本没有褪色效果。

有什么想法吗?

$(".myclass ul li:eq(" + $(this).attr("href") + ")").fadeIn(5000); 

它所获得的href属性只是保存一个表示ul li长度位置的数值。

5 个答案:

答案 0 :(得分:3)

我遇到了同样的问题并使用了下面的代码(来自上面Q8-coder发布的链接)。它运作良好,但我仍然有一些问题。我注意到在具有相对或绝对定位的子容器的容器元素上使用fadeTo在IE8中不起作用。父母会褪色,但所有具有正面或相对位置的儿童元素仍然会被看到。解决它的唯一方法是使用jQuery选择容器元素及其所有子元素,然后将所有这些元素应用于fadeTo。

jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 

jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 

jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 

答案 1 :(得分:1)

试试这个workaround

答案 2 :(得分:1)

对我来说,使用fadeIn()工作正常,我的<div>可以很好地淡入IE9,然后(一旦淡入淡出完成)它将再次消失。啊。

修复是添加此处显示的filter css值:

$("#fadeMeIn").fadeIn("slow");
$("#fadeMeIn").css('filter', 'none');

答案 3 :(得分:0)

试试这个:

$(".myclass ul li:eq(" + $(this).attr("href") + ")").hide().fadeIn(5000);

答案 4 :(得分:0)

我在IE8中遇到了类似的问题。设置z-index后,问题就消失了。我在下面找到了解决方案。

http://www.kevinleary.net/jquery-fadein-fadeout-problems-in-internet-explorer/