LSRONG-双荣设计
扫描二维码添加QQ好友

扫一扫二维码,加我QQ

调用广告位倒计时效果

2016-03-27 11:03:17ecshop常见问题

在制作模板时,我们经常会碰到调取广告的倒计时效果,现在有方法了,简单而且又便捷。就要68ecshop的技术来为大家简单的介绍下吧!

第一步 在模板文件中有个php文件夹,打开init.php文件,搜索get_advlist

要sql后追加,意思就是在$sql = "select ap.ad_width,ap.ad_height,ad.ad_id,ad.ad_name,ad.ad_code,后面添加搜索字段ad.ad_link,ad.link_man,ad.start_time,ad.end_time,


在$arr[$row['ad_id']]['name'] = $row['ad_name'];

下面添加

$arr[$row['ad_id']]['link_man'] = $row['link_man'];
                $arr[$row['ad_id']]['etime'] = $row['end_time'];
                $arr[$row['ad_id']]['stime'] = $row['start_time'];
               
               
                    $time = gmtime();
        if ($time >= $row['start_time'] && $time <= $row['end_time'])
        {
            $arr[$row['ad_id']]['etime'] = local_date('M d, Y H:i:s',$row['end_time']);
        }
        else
        {
            $arr[$row['ad_id']]['etime'] = 0;
        }




第二步  在你添加广告倒计时位置添加(我这里是给首页的热门活动部分添加的广告位倒计时)

   <?php
$GLOBALS['smarty']->assign('temai',get_advlist('首页热门活动广告位', 20));
?>  
          <script >
var Tday = new Array();
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
var DifferHour = -1
var DifferMinute = -1
var DifferSecond = -1
function clock(key,num)
{
   var time = new Date()
   var hour = time.getHours()
   var minute = time.getMinutes()
   var second = time.getSeconds()
   var timevalue = ""+((hour > 12) ? hour-12:hour)
   timevalue +=((minute < 10) ? ":0":":")+minute
   timevalue +=((second < 10) ? ":0":":")+second
   timevalue +=((hour >12 ) ? " PM":" AM")
   var convertHour = DifferHour
   var convertMinute = DifferMinute
   var convertSecond = DifferSecond
   var Diffms = Tday[key].getTime() - time.getTime()
   DifferHour = Math.floor(Diffms / daysms)
   Diffms -= DifferHour * daysms
   DifferMinute = Math.floor(Diffms / hoursms)
   Diffms -= DifferMinute * hoursms
   DifferSecond = Math.floor(Diffms / Secondms)
   Diffms -= DifferSecond * Secondms
   var dSecs = Math.floor(Diffms / microsecond)
 
   if(convertHour != DifferHour) a="<font color=#666>"+DifferHour+"</font>天";
   if(convertMinute != DifferMinute) b="<font color=#666>"+DifferMinute+"</font>时";
   if(convertSecond != DifferSecond) c="<font color=#666>"+DifferSecond+"</font>分"
     d="<font color=#666>"+dSecs+"</font>秒"
     if (DifferHour>0) {a=a}
     else {a=''}
   document.getElementById("leftTime"+num+key).innerHTML = a + b + c + d; //显示倒计时信息


}
</script>




 <div class="title"><i>火</i>热门活动</div>
          <ul>
           <!-- {foreach from=$temai item=ad name=index_image key=key}-->
            <li>
              <dl style="background-image:url({$ad.image})">
                <dt>{$ad.link_man}</dt>
 <dd class="time"><span class="sell">倒计时</span> <span class="time-remain" id="leftTime1{$key}"> {$lang.please_waiting} </span></dd>
              </dl>
            </li>
             <script>
Tday[{$key}] = new Date("{$ad.etime}");  
window.setInterval(function()    
{clock({$key},1);}, 1000);    
</script>
            <!-- {/foreach}-->  
          </ul>

文章关键词