0

我有这个 jQuery 脚本,它在有人投票时添加了一个计时器,他需要等待 3 分钟

脚本一直在工作,直到我用 php 获得剩余时间

$(document).ready(function(){
alert("1");
 function Timer(dur, par, can, cnt) {
var parent = $(par),
    canvas = can ? $(can, parent)[0] : $('.timer', parent)[0],
    seconds = cnt ? $(cnt, parent)[0] : $('.counter', parent)[0],
    sec = dur,
    countdown = sec;    

if (!canvas)
    canvas = $("<canvas>").addClass('timer')
        .attr('width', 100).attr('height', 100).appendTo(parent)[0];

if (!seconds)
    seconds = $("<span>").addClass('counter').appendTo(parent)[0];

var ctx = canvas.getContext('2d');
ctx.lineWidth = 8;
ctx.strokeStyle = "#528f20";

var startAngle = 0,
    time = 0,
    intv = setInterval(function() {
        var endAngle = (Math.PI * time * 2 / sec);
        ctx.arc(65, 35, 30, startAngle, endAngle, false);
        ctx.clearRect(0, 0, 200, 200);

        startAngle = endAngle;
        ctx.stroke();

        countdown--;
        if (countdown > 60) {
            seconds.innerHTML = Math.floor(countdown / 60);
            var ss = countdown % 60;
            if (ss < 10) 
                ss = "0" + ss;
            seconds.innerHTML += ":" + ss;
        }
        else {
            seconds.innerHTML = countdown;
        }

        if (++time > sec, countdown == 0) {
            clearInterval(intv);
            $(canvas).remove();
            $(seconds).remove();
            /*$(par).prepend('<img id="theImg" src="http://ivojonkers.com/votify/upvote.png" />');*/
        }
    }, 1000);}



$(".upvote").click(function(){
    alert("2");
    var par = $("<div>").addClass("time").appendTo("#timers");
    Timer(Math.round(180), par);
});
if (<?php echo $wait; ?> > 0) {
var par = $("<div>").addClass("time").appendTo("#timers");
Timer(Math.round(<?php echo $wait; ?>, par); } });

所以在这一部分中,我有时间等待下一次用 php 投票,这似乎不起作用出了什么问题?

if (<?php echo $wait; ?> > 0) {
var par = $("<div>").addClass("time").appendTo("#timers");
Timer(Math.round(<?php echo $wait; ?>, par); } });
4

2 回答 2

0

您应该只使用 asetTimeout(function(){},(3 * 60 * 1000))来阻止投票功能。

//Block the vote here
setTimeout(function(){/*unblock here*/},(3 * 60 * 1000))
于 2012-11-03T16:49:10.210 回答
0

替换这个:

Timer(Math.round(<?php echo $wait; ?>, par); } });

和:

Timer(Math.round(<?php echo $wait; ?>, par)); } });

;)

于 2012-11-03T16:51:52.910 回答