查看示例:DEMO
XHTML復制代碼 代碼如下:
 
<div> 
<div> 
<a href="#"><img src="images/0.jpg" /></a> 
<div> 
<p><strong><a href="http://m.survivalescaperooms.com">Shuro</a></strong><span> 
8分鐘前</span> 說:</p> 
<div>評論內(nèi)容。。。</div> 
</div> 
</div> 
... 
</div> 
復制代碼 代碼如下:
 
#demo{width:400px; height:80px; margin:80px auto; border-bottom:1px dotted #d3d3d3} 
.saylist{margin:8px auto; height:80px; padding:4px 0;} 
.saylist img{float:left; width:50px; margin:4px} 
.saytxt{float:right; width:320px; overflow:hidden} 
.saytxt p{line-height:18px} 
.saytxt p strong{margin-right:6px} 
.saytxt p span{color:#999} 
.say{margin-top:3px; font-size:14px; font-weight:bold} 
復制代碼 代碼如下:
 
function formatSay($say,$dt,$uid){ 
$say=htmlspecialchars(stripslashes($say)); 
return' 
<div><a href="#"><img src="images/'.$uid.'.jpg" 
height="50" /></a> 
<div> 
<p><strong><a href="#">demo_'.$uid.'</a></strong> <span>'.tranTime($dt).'</span> 說: 
</p><div>'.$say.'</div> 
</div> 
<div></div> 
</div>'; 
} 
復制代碼 代碼如下:
 
function tranTime($stime) { 
$rtime = date("m-d H:i",$stime); 
$htime = date("H:i",$stime); 
$day_time = date("j",$stime); 
$today=date("j",time()); 
$ds = $today - $day_time; 
$time = time() - $stime; 
if ($time < 60) { 
$str = '剛剛'; 
} 
elseif ($time < 60 * 60) { 
$min = floor($time/60); 
$str = $min.'分鐘前'; 
} 
elseif ($time < 60 * 60 * 24) { 
$h = floor($time/(60*60)); 
$str = $h.'小時前 '.$htime; 
if($ds==1) 
$str = '昨天 '.$rtime; 
} 
elseif ($time < 60 * 60 * 24 * 2) { 
$str = '昨天 '.$rtime; 
if($ds==2) 
$str = '前天 '.$rtime; 
}elseif($time < 60 * 60 * 24 * 3){ 
$str = '前天 '.$rtime; 
if($ds>2) 
$str = $rtime; 
} 
else { 
$str = $rtime; 
} 
return $str; 
} 
復制代碼 代碼如下:
 
require_once('connect.php'); //連接數(shù)據(jù)庫文件 
require_once('function.php'); //函數(shù)文件 
$query=mysql_query("select * from say order by id desc limit 0,15"); 
while ($row=mysql_fetch_array($query)) { 
$sayList.=formatSay($row[content],$row[addtime],$row[userid]); 
} 
復制代碼 代碼如下:
 
<div> 
<?php echo $sayList;?> 
</div> 
復制代碼 代碼如下:
 
$(function(){ 
//除了顯示第一個saylist,其他的都隱藏 
$(".saylist").hide().eq(0).show(); 
//自循環(huán)函數(shù),循環(huán)展示信息 
(function showNextSay(){ 
//每條信息展示7.5秒 
$(".saylist:visible").delay(7500).fadeOut("slow",function(){ 
$(this).appendTo("#demo"); 
//展示下一條 
$(".saylist:first").fadeIn("slow",function(){ 
//再次調(diào)用函數(shù) 
showNextSay(); 
}); 
}); 
})(); 
}); 
新聞熱點
疑難解答