jQuery pasttimes: 計算已經消逝的時間

仿製 Facebook 塗鴉牆上各個訊息的貼文經過時間,例如 3 分鐘前、3 小時前或 3 天前的自動計算功能。

安裝

<script type="text/javascript" src="jquery.pasttimes.js"></script>

參數說明

方法說明

下載位置

範例: 預設值

Post at .
Post at .
Post at .
Post at .
Post at .
$(function(){
  $('#past').pasttimes();
});

範例: 指定 target, label

發表於 .
HTML
<div class="past1">
  發表於  <a href="javascript:;" class="past" title="<?php echo date('Y-m-d H:i:s', time() - 300); ?>"></a>.
</div>
javascript
$('.past1').pasttimes({
  target: 'a.past',
  label: [' 秒前', ' 分鐘前', ' 小時前', ' 天前']
});

範例: 日期輸出格式, ontimeup 事件, destroy 方法

Post at .

HTML
<div class="past2">
  Post at  <span class="past" title="<?php echo date('Y-m-d H:i:s', time() - 3600); ?>"></span>.
</div>
javascript
$('.past2').pasttimes({
  format: 'j M Y H:i:s',
  ontimeup: function () {
    console.log('Time\'s up');
  }
});
$(':button').click(function () {
  $('.past2').pasttimes('destroy');
});

意見