Jquery 不透明度不适用于IE8
这会使Firefox/Chrome中的图层淡入淡出,但在IE8中,它不会使图层不透明度Jquery 不透明度不适用于IE8,jquery,Jquery,这会使Firefox/Chrome中的图层淡入淡出,但在IE8中,它不会使图层不透明度 $('document').ready(function () { $('.out-of-stock').each(function () { $('.productImage', $(this)).css('opacity', '.25'); $('.stockMessage', $(this)).removeClass('stockMessageOff'); $('.stock
$('document').ready(function () {
$('.out-of-stock').each(function () {
$('.productImage', $(this)).css('opacity', '.25');
$('.stockMessage', $(this)).removeClass('stockMessageOff');
$('.stockMessage', $(this)).addClass('stockMessageOn');
$('.stockMessage.stockMessageOn', $(this)).css('opacity', '1').text('Sold Out');
});
});
我读过几篇关于分配缩放的stackoverflow帖子:1;到css类,但这并没有解决它
有什么想法吗?:) 这应该适用于IE8
$('.productImage', $(this)).css('-ms-filter','progid:DXImageTransform.Microsoft.Alpha(Opacity=25)');
要获得跨浏览器支持,请尝试使用以下方法:
$('.productImage', $(this)).css({'-ms-filter':'progid:DXImageTransform.Microsoft.Alpha(Opacity=25)','filter':'alpha(opacity=25)','-moz-opacity':'0.25','-khtml-opacity':'0.25','opacity':'0.25'});
使用以下命令:
$('.productImage').fadeTo('fast', .25);
希望能有所帮助。如本页所述:IE8(及以下)不支持不透明度,因此您必须使用Fabian提供的相当笨拙的代码 我认为一个更简单的选择是按照Madmartigan的建议,使用jQuery的fadeTo()-方法,因为它将满足所有现代(但不是那么现代)浏览器的需要:
$('.productImage').fadeTo(0, .25);
我还注意到您的代码中有一些可以改进的地方。仅使用.class选择器比提供标记名慢,而且jQuery必须遍历每个元素并匹配类,而不仅仅是img(例如)元素。您也没有利用jQuery链接方法调用的能力,这不仅加快了一点速度,而且使代码更加整洁:
$(function () {
$('div.out-of-stock').each(function () {
$('img.productImage', this).css('opacity', '.25');
$('p.stockMessage', this).removeClass('stockMessageOff').addClass('stockMessageOn').css('opacity', '1').text('Sold Out');
});
});
只是一个提示!:)