Adi*_*dis 14 jquery internet-explorer cleartype
我正在经历一些非常奇怪的事情!
我有一个div,我隐藏着JS(jQuery).像这样:
$('#myDiv').hide();
Run Code Online (Sandbox Code Playgroud)
然后,当我像这样做一个淡入淡出:
$("#myDiv").fadeIn('slow');
Run Code Online (Sandbox Code Playgroud)
然后文本在IE中丢失ClearType但在FF中丢失.如果我选择fadeIn的切换,那么一切都很好.
IE是什么,有什么解决方案,因为它看起来很糟糕. (我在这一点上可能已经理解了ClearType)
Aro*_*eel 24
快速搜索主题显示以下内容:
jQuery fadeIn/fadeOut IE cleartype故障
问题似乎是CSS"过滤器"属性不会自动删除.解决此问题的最简单方法是手动删除它:
$('#myDiv').fadeIn('slow', function() {
this.style.removeAttribute('filter');
});
Run Code Online (Sandbox Code Playgroud)
正如上面的博客文章所解释的那样,这是一个相当混乱的解决方案.
摘自博客文章,包括解决此问题的更清晰的解决方案:
这意味着我们每次想要淡化元素时,都需要删除filter属性,这会使我们的代码看起来很乱.
一个简单,更优雅的解决方案是通过jQuery的插件接口将.fadeIn()和.fadeOut()函数与自定义函数包装在一起.代码完全相同,但我们不是直接调用淡入淡出函数,而是调用包装器.像这样:
$('#node').customFadeOut('slow', function() {
//no more fiddling with attributes here
});
Run Code Online (Sandbox Code Playgroud)
那么,你如何使这个工作?在包含用于添加功能的jQuery库之后,只需包含以下代码.
(function($) {
$.fn.customFadeIn = function(speed, callback) {
$(this).fadeIn(speed, function() {
if(jQuery.browser.msie)
$(this).get(0).style.removeAttribute('filter');
if(callback != undefined)
callback();
});
};
$.fn.customFadeOut = function(speed, callback) {
$(this).fadeOut(speed, function() {
if(jQuery.browser.msie)
$(this).get(0).style.removeAttribute('filter');
if(callback != undefined)
callback();
});
};
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9831 次 |
| 最近记录: |