Dan*_*ugg 2 jquery internet-explorer cross-browser
这似乎在IE8中失败了(没有测试过7,但肯定也会失败)value函数返回undefined.它在Firefox中工作正常:
$('selector').css('property', function(index, value){ alert(value); });
Run Code Online (Sandbox Code Playgroud)
我脚本中的实际代码如下:
$('.scrollBkg').css('background-position', function(index, value){
var backgroundPosition = value.split(' ');
return (parseFloat(backgroundPosition[0]) + (($(this).hasClass('scrollLeft') ? -1 : 1) * parseInt($(this).css('z-index'))) / 2) + 'px ' + backgroundPosition[1];
});
Run Code Online (Sandbox Code Playgroud)
为什么说value是undefined在IE浏览器?相反,我怎样才能按预期工作呢?
在MSIE中检索backgroundPositionY和backgroundPositionX而不是backgroundPosition
var backgroundPosition = (document.all && !window.opera)
?[$(this).css('backgroundPositionX'),
$(this).css('backgroundPositionY')]
: value.split(' ');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2915 次 |
| 最近记录: |