douchu4048 2015-04-21 07:43
浏览 71

在php中设置后台计时器

I like to do a "background timer" but I don't know how. The main things: I have if, and if I go in I like to set the time, and start a timer ($ido = $split[0]*60*60 + $split[1]*60 + $split[2]; sleep($ido);), and after this timer end, I like to run a function ($jatek->epuletkesz();) but, after this if, I have another things, and if i start sleep the page loading is stop because wait for the sleep end. But I like, the sleep go in "background" and don't stop the page things, only the one function run after sleep end. (Sorry for bad English, I hope u can understand my problem.)

Here is the code:

if(empty($üzi)) {
    echo "<script type='text/javascript'>alert('Sikeres fejlesztés!');</script>";

    $nyers = $jatek->kovnyers($epulet);

    $split = explode(":", $nyers['epetesiido']);
    $ido = $split[0]*60*60 + $split[1]*60 + $split[2];
    sleep($ido);
    $jatek->epuletkesz();
    //header( 'Location: ../views/jatek.php' );
}
  • 写回答

2条回答 默认 最新

  • dongrou2920 2015-04-21 08:06
    关注

    Well one possible solution is that you generate some classes in you css with different background. Like this :

    .background1 {
        background: url('../img/img1.jpg');
    }
    
    .background2 {
        background: url('../img/img1.jpg');
    }
    

    In javascript you need a function to change the background like :

    /**
     * elem jquery elemnt to update
     * background class to add
     */
    var updateBackground = function(background, elem) {
        var bck_list = ['background1', 'background2'];
        elem.addClass(active);
    
        jQuery.each(bck_list, function( index, value ) {
            if (value !== active) {
                elem.removeClass(value);
            } else {
                var next_index = index + 1;
            }
        });
    
        // check if the next background exists
        if (bck_list[next_index] === undefined) {
             next_index = 0;
        }
    
        setTimeout(function(){ updateBackground(bck_list[next_index], elem); }, 30000);
    }
    

    At the end a timer :

    setTimeout(function(){ updateBackground("background1", $('#elem_to_update')); }, 30000);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?