新着情報に使える便利なJavaScriptです。
かたつむりくんのwww 『一定時間で自動的に消える New マークを付ける JavaScript の jQuery 版』
画像でもテキストでも表示できるように、丁寧にソース紹介もされています。
ちなみに、wordpressではこちらのjsを使用させていただきました。
jQuery(document).ready(function(){
var currentDate = new Date();
jQuery(‘.newmarkList’).each(function(){
var pass // passage time
= 72;
var content // display content
= ‘<img class=”newmark” src=”/img/icon/newmark.gif” alt=”3日以内の新着ブログ記事” width=”15″ height=”15″ title=”3日以内の新着ブログ記事”/>’;
var newmarkAttr = $(this).attr(‘title’);
newmarkAttr = newmarkAttr.replace(/年|月|日|時|分/g,’:’);
newmarkAttr = newmarkAttr.replace(/\s|秒.*/g,”);
var time = newmarkAttr.split(“:”);
var entryDate = new Date(time[0], time[1]-1, time[2], time[3], time[4], time[5]);
var now = (currentDate.getTime() – entryDate.getTime())/(60*60*1000);
now = Math.ceil(now);
if(now <= pass){
jQuery(this).after(content);
}
});
});