修复IE中的背景位置 [英] Fix for background-position in IE
问题描述
运行一段使用jquery和2个jquery插件的代码时,我在IE7中遇到了这个问题。该代码适用于FF3和Chrome。
I get this problem in IE7 when running a piece of code that uses jquery and 2 jquery plugins. The code works in FF3 and Chrome.
完整错误是:
Line: 33
Char: 6
Error: bg is null or not an object
Code: 0
URL: http://localhost/index2.html
但是第33行是一个空行。
However line 33 is a blank line.
I我正在使用2个插件:draggable和zoom。无论我对代码做什么,总是第33行出错。我通过查看源检查源是否有更新,但我觉得这可能对我说谎。
I am using 2 plugins: draggable and zoom. No matter what I do to the code it is always line 33 that is at fault. I check the source has update via view source but I feel this could be lying to me.
<body>
<div id="zoom" class="zoom"></div>
<div id="draggable" class="main_internal"><img src="tiles/mapSpain-smaller.jpg" alt=""></div>
<script type="text/javascript">
$(document).ready(function() {
$('#draggable').drag();
$('#zoom').zoom({target_div:"draggable", zoom_images:new Array('tiles/mapSpain-smaller.jpg', 'tiles/mapSpain.jpg') });
});
</script>
</body>
基本上我要做的是用jQuery重新创建Pragmatic Ajax地图演示。
Essentially what I am trying to do is recreate the Pragmatic Ajax map demo with jQuery.
看来这段代码的第二行造成了麻烦:
It would appear that the second line of this snippet is causing the trouble:
bg = $(this).css('background-position');
if(bg.indexOf('%')>1){
似乎试图选择 #draggable
的背景位置属性而不是找到它?手动添加后台位置:0 0;
没有修复它。关于如何解决这个问题的任何想法?
It seems to be trying to select the background-position property of #draggable
and not finding it? Manually adding a background-position: 0 0;
didn't fix it. Any ideas on how to get around this problem?
我尝试使用MS Script Debugger但这几乎没用。无法检查变量或其他任何内容。
I tried using the MS Script Debugger but that is nearly useless. Can't inspect variables or anything else.
推荐答案
关于Interweb的更多挖掘揭示了答案:IE没有'了解选择器 background-position
。它理解非标准 background-position-x
和 background-position-y
。
A bit more digging about on the Interweb has revealed the answer: IE doesn't understand the selector background-position
. It understands the non-standard background-position-x
and background-position-y
.
目前正在共同攻击某些东西以解决问题。
Currently hacking something together to workaround it.
很好的一个,Redmond。
Nice one, Redmond.
这篇关于修复IE中的背景位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!