因为腾讯给的接口有刷新限制,新手每小时1000次,平均算下来4.几秒一次,很明显并不是每次都能成功获取的,所以我重写了加载函数,0.5秒加载一次,直到成功为止.另外,我还重写了显示函数,鼠标移过的时候会自动伸展显示下面的内容,左击右击切换的功能依然还在,但自动翻页被我去掉了,已经用处不大了....
下面是代码...
var MouseIn = false;
var Timer = false;
var TimeOut = 500;
function ScrollU(obj){
$(obj).find("ul:last").animate({
marginTop:"+16px"
}, 250, function(){
$(this).css({marginTop:"0px"}).find("li:last").prependTo(this);
});
}
function ScrollD(obj){
$(obj).find("ul:first").animate({
marginTop:"-16px"
}, 250, function(){
$(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
});
}
function getTime(t){
var nowDate = new Date(t*1000);
var _format = function(n) { return n = n < 10 ? '0' + n : n; }
var _lformat = function(n) { return n = (n > 60 && n < 1900) ? n + 1900 : n; }
var diff = parseInt(nowDate.getTime()/1000) - parseInt(t);
if(diff < 60*24*30*12){
return (nowDate.getMonth() + 1)+'月'+_format(nowDate.getDate())+'日' + ' ' +_format(nowDate.getHours())+':'+_format(nowDate.getMinutes());
} else {
return _lformat(nowDate.getYear())+'年'+(nowDate.getMonth() + 1)+'月'+_format(nowDate.getDate())+'日' + ' ' +_format(nowDate.getHours())+':'+_format(nowDate.getMinutes());
}
}
function weiboData(d){
clearInterval(Timer);
TimeOut = 3000;
for(i in d.data){
if(d.data[i].nick.length > 45) d.data[i].nick.substr = d.data[i].nick.substring(0, 45) + '...';
switch(d.data[i].type){
case 1:
var type = '广播';
break;
case 2:
var type = '转播';
break;
case 3:
continue;
break;
case 4:
var type = '对话';
break;
}
var text = '<li><span class="left">'+ type +': '+ d.data[i].content +
'</span><span class="right">'+getTime(d.data[i].timestamp)+' 来自: '+d.data[i].fromarea+'</span></li>';
$('#notice ul').append(text);
}
$('#notice').bind('contextmenu', function(){return false});
$('#notice').bind('mousedown', function(e){
$(this).stop();
if (e.which == 1){
$(this).animate({
height: ($(this).find('ul li:eq(1) span').height()-3)+'px'
}, 300);
ScrollD("#notice");
} else if (e.which == 3){
$(this).animate({
height: ($(this).find('ul li:last span').height()-3)+'px'
}, 300);
ScrollU("#notice");
}
return false;
});
$('#notice').live('mouseover', function(){
$(this).stop();
$(this).animate({
height: ($(this).find('ul li:first span').height()-3)+'px'
}, 300);
MouseIn = true;
});
$('#notice').live('mouseout', function(){
$(this).stop();
$(this).animate({
height: '15px'
}, 200);
MouseIn = false;
});
$('#notice ul li[class=first]').remove();
}
function noticeInit(){
$.getScript('http://v.t.qq.com/output/json.php?type=1&name=tinystrong&sign=8efce5b1f39e7a2f9a833387f82d02c1586ac456');
}
$(document).ready(function(){
Timer = setInterval('noticeInit()', TimeOut);
});

非常赞!
@宅男小强
赞喔
不错不错,谢谢分享了。