2010-04-27 36 views
1

我的页面上没有默认的背景图像CSS。在加载时,它被设置为jQuery的初始图像,等待10秒钟,然后从一些预定图像加载一个随机图像。有上一个和下一个按钮可让您循环浏览图像。在ie6中加载初始图像,然后在10秒后加载一张随机图像,但按prev/next会导致背景变白并且图像不加载。有了警报,我能够发现它仍然跟踪它应该加载的图像的位置和URL,但不会加载它。这是下面的代码。在IE6中使用jquery不会改变背景图像

<script type="text/javascript"> 
    var facts = new Array(); 
    var position; 
    $(document).ready(function() { 
     <xsl:for-each select="$currentPage/ancestor-or-self::node[@level=1]/../node[@nodeName='Fun Fact Folder']/node"> 
      facts[<xsl:value-of select="position()" />] = '<xsl:value-of select="." />'; 
     </xsl:for-each> 
     if(window.location.pathname == "/homepage.aspx" || window.location.pathname == "/") { 
      $(".fun_facts_bg").css("background-image", "url(images/fun_fact_homepage.JPG)"); 
      setTimeout("randomFact()",10000); 
     } else { 
      randomFact(); 
     } 
    }); 
    function randomFact() { 
     $("a.previous_button").css("display", "block"); 
     $("a.next_button").css("display", "block"); 
     position = Math.ceil(Math.random() * (facts.length - 1)); 
     changeFact(0); 
    } 
    function changeFact(increment) { 
     position = checkPosition(position, increment); 
     $(".fun_facts_bg").css("background-image", "url(" + facts[position] + ")"); 
    } 
    <xsl:text disable-output-escaping="yes">&lt;!--//--&gt;&lt;![CDATA[//&gt;&lt;!-- 
    function checkPosition(currentPos, increment) { 
     currentPos = currentPos + increment; 
     if (currentPos &gt; facts.length - 1) { 
      currentPos = 1; 
     } else if (currentPos &lt; 1) { 
      currentPos = facts.length - 1; 
     } 
     return currentPos; 
    } 
    //--&gt;&lt;!]]&gt;</xsl:text> 
</script> 

<a class="previous_button" href="javascript:void(0);" onclick="changeFact(-1);"> 
<a class="next_button" href="javascript:void(0);" onclick="changeFact(1);"> 

回答

0

我敢肯定你应该在某处使用模数来确保你保持在预定的范围内。这可能有帮助。