English 中文(简体)
正在绕过铬和 FF 背景选项卡处理 Javascript 时的处理错误
原标题:Getting round the chrome and FF background tab processing errors for javascript

Ok 我一整天都在忙这个 我却不能说出去

我有一个使用SetTimeout () 的缩写幻灯片。 我理解在铬和一些FF版本中, 它会减慢速度, 减少 cpu 使用量, 然后加快速度, 赶上我回到幻灯片中应该放在哪里。

然而,在这样做的时候,它不仅加快了速度,而且还忽略了我的代码中的一些问题,即跳出我的图像阵列,造成一个短暂的未定义的错误。 是什么只是被困住了, 一旦它赶上了它, 它就会运行顺利???? 隐藏了我如何绕过它以及如何阻止它加速呢? 这是我所使用的代码 。

<script type="text/javascript">
<?php 
$fetch_images = mysql_query($Aquery);
$fetch_title = mysql_query($Bquery);
$fetch_text = mysql_query($Cquery);
$num_rows =  mysql_num_rows($fetch_images);
?>
var i=0;
var products  = [<?php while($image = mysql_fetch_array($fetch_images)){echo " ".$image[ imageurl ]." ,";}?>];
var productstitle  = [<?php while($title = mysql_fetch_array($fetch_title)){echo " ".$title[ title ]." ,";}?>];
var productstext  = [<?php while($text = mysql_fetch_array($fetch_text)){echo " ".stripslashes($text[ strapline ])." ,";}?>];
function slideShow<?php echo $timerTag;?>(){
    if (i<=(products.length-1)){
        $( #headerslideimage ).fadeTo("slow", 0, function() {
        <?php if(page( pageurl ) !=  home ){?>
            document.getElementById( headerslidetitle ).innerHTML=productstitle[i];
            document.getElementById( headerslidetext ).innerHTML=productstext[i];
        <?php }?>
        document.getElementById( headerslideright ).innerHTML="<img id= headerslideimage  src= "+products[i]+"  alt= "+productstitle[i]+" />";
        i++;
        $( #headerslideimage ).fadeTo(4000, 100, function() {});
    });
} else {
    i = 0;
    $( #headerslideimage ).fadeTo("slow", 0, function() {
    <?php if(page( pageurl ) !=  home ){?>
    document.getElementById( headerslidetitle ).innerHTML=productstitle[i];
    document.getElementById( headerslidetext ).innerHTML=productstext[i];
    <?php }?>
    document.getElementById( headerslideright ).innerHTML="<img id= headerslideimage  src= "+products[i]+"  alt= "+productstitle[i]+" />";
    i++;
    $( #headerslideimage ).fadeTo(4000, 100, function() {});
});
}
setTimeout("slideShow<?php echo $timerTag;?>()", 5000);
}
问题回答

您的动画函数之一最终会调用 request AAnimationFrame ? secet Interval seteTimeout 不会在您最小化或切换标签时停止运行,而是 request AAnimationFrame 这样做。结果是,如果您从一个间隔(或链串超时)调调调调调调调来 请求 AimationFrame 任务,您会不断排队,在标签再次聚焦时快速运行。

检查这个相关的问题: < a href=""https://stackoverflow.com/ questions/7739657/jquery-setinterval-on-minminimize" >Jquery设置“Interval on 最小化

使用 < a href=> "https:// developmenter.mozilla.org/en/DOM/Using_the_Page_Vibility_API" rel=“no follow” >Page Visibility API 在您的函数中检查页面是否可见。 如果它没有跳过执行任何迭代内容, 这将增加在用户不与您的页面互动时使用更少的用户资源的好处 。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签