如何通过倒计时更改保证金值?

时间:2013-04-01 19:39:11

标签: javascript jquery timer margin countdowntimer

有人能帮我这个吗?

这是我现在拥有的 http://jsfiddle.net/fergu0516/GAVDA/

        var leave = 200;
        if(leave > 0)
        {
            CounterTimer();
        }
        function CounterTimer() 
        {
        var minute = Math.floor(leave / 60);
        var second = Math.floor(leave) - (minute*60);            
        minute=minute<10 ? "0" + minute : minute; 
        second=second<10 ? "0" + second : second;

        var remain = minute + ":" + second;
        leave = leave-1 ;
        document.getElementById("clkTimer").innerHTML = remain;            


        if(leave >= 0)
          {
              setTimeout(CounterTimer,1000);
          }
        else
          {
            alert("Your cart is expired!")
            window.location = "#";                
          }
        }
    $(document).ready(function(){

// The relative URL of the submit.php script.
// You will probably have to change it.

// Caching the feedback object: 
var feedback = $('#feedback');

$('#feedback').click(function(){

    // We are storing the values of the animated
    // properties in a separate object:

    var anim    = {     
        mb : 207,           // Margin Bottom
        pt : 0          // Padding Top
    };

    var el = $(this).find('.arrow');

    if(el.hasClass('buttonright')){
        anim = {
            mb : 0,
            pt : 0
        };
    }

    // The first animation moves the form up or down, and the second one 
    // moves the "Feedback heading" so it fits in the minimized version

    feedback.stop().animate({marginRight: anim.mb});

    feedback.find('.section').stop().animate({paddingTop:anim.pt},function(){
        el.toggleClass('buttonright buttonleft');
    });
});

    });

我需要与样本具有相同的效果:现在发生的是当我按下红色框时,计时器显示(div id =&#34; feedback&#34;)207px的边距权限。

我需要的是当时间到达1点时自动发生这种情况。因此,当计时器到达1:00时,窗口将显示,通过向对象添加margin-right:207px。

非常感谢,一切都会有所帮助。

3 个答案:

答案 0 :(得分:2)

Demo

做这样的事情:

    if(leave == 60){
        $('#feedback').trigger('click');
    }

答案 1 :(得分:1)

添加

if (leave == 60)
{
   $('#feedback').stop().animate({marginRight: 207});   
}

CounterTimer()函数。也许在leave = leave - 1;行之后。

答案 2 :(得分:0)

您只需添加if语句即可查找if(leave == 60),如果是,则可以将该元素设置为“可见”margin-right值。