magento 预售倒计时功能

1.首先需要在后台设置一个date属性的产品属性 为预售的日期

2.然后 是取出这个属性值$_product->getResource()->getAttribute('code')->getFrontend()->getValue($_product);

取出的是一个string类型的时间数据,要使用strtotime()函数将时间转化成时间戳,然后获得当前的时间 两者相减就是倒计时的秒数

3.使用js显示倒计时

var intDiff = parseInt(time);//time是倒计时总秒数量
function timer(intDiff){
    window.setInterval(function(){
    var day=0,
        hour=0,
        minute=0,
        second=0;//时间默认值        
    if(intDiff > 0){
        day = Math.floor(intDiff / (60 * 60 * 24));
        hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
        minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
        second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
    }
    if (minute <= 9) minute = '0' + minute;
    if (second <= 9) second = '0' + second;
    jQuery('#day_show').html(day+" days, ");
    jQuery('#hour_show').html('<s id="h"></s>'+hour+':');
    jQuery('#minute_show').html('<s></s>'+minute+':');
    jQuery('#second_show').html('<s></s>'+second);
    intDiff--;
    }, 1000);
}
jQuery(function(){
    timer(intDiff);
});

  

posted on 2014-10-22 16:53  怕淹死的鱼  阅读(534)  评论(0编辑  收藏  举报

导航