欢迎来到福编程网,本站提供各种互联网专业知识!

javascript实现轮显新闻标题链接

发布时间:2007-08-13 作者: 来源:转载
用两个div嵌套链接文字,最外面的div设置overflow:hidden,并用js动态控制它的width,实现伸展与收缩。新闻轮显的demoa{font-size:14px}#box{width:400px;height:20px;overflow:hidden;}#title{color:#000;width:400px;height:20px;font-size:14px;line-heigh
用两个div嵌套链接文字,最外面的div设置overflow:hidden,并用js动态控制它的width,实现伸展与收缩。





新闻轮显的demo

a{font-size:14px}
#box{width:400px;height:20px;overflow:hidden;}
#title{color:#000;width:400px;height:20px;font-size:14px;line-height:18px;/*background-color:#FF0000*/}


varhandle;
varhandle2;
varboxW=0;
vartitleNum=0;
functioninit(){
varnewsTitles="快乐笛子的博客|中央统战部:新社会阶层纳入中国统一战线|中俄明年将在俄远东地区举行联合反恐演|广州宾馆3小时内须将旅客信息传给公安机关|国亲将推动弹劾陈水扁案";
varnewsLinks="http://www.happyshow.org|http://news.sina.com.cn/c/2006-09-02/093410901015.shtml|http://news.sina.com.cn/c/2006-09-02/02069914065s.shtml|http://news.sina.com.cn/c/2006-09-02/043210898986.shtml|http://news.sina.com.cn/c/2006-09-02/06069915455s.shtml";
document.getElementById("box").style.width="400px";
document.getElementById("title").innerHTML=""+newsTitles.split("|")[titleNum]+"";
//setTimeout("decreaseBoxW();",1500);
titleNum++;
setInterval("innerTitle('"+newsTitles+"','"+newsLinks+"')",3100);
}
functioninnerTitle(titles,links){
vart=titles.split("|");
vara=links.split("|");
if(!t[titleNum])
titleNum=0;
document.getElementById("box").style.width="0px";
document.getElementById("title").innerHTML=""+t[titleNum]+"";
handle2=setInterval("increaseBoxW()",1);//展开
titleNum++;
}
functionincreaseBoxW(){
boxW=parseInt(document.getElementById("box").style.width);
boxW=boxW+4;
if(boxW>400){
clearInterval(handle2);
document.getElementById("box").style.width="400px";
setTimeout("decreaseBoxW()",1500)
}else{
document.getElementById("box").style.width=boxW+"px";
}
}
functiondecreaseBoxW(){
handle=setInterval("decreaseBoxW2()",4)
}
functiondecreaseBoxW2(){
boxW=parseInt(document.getElementById("box").style.width);
boxW=boxW-16;
if(boxW<0){
clearInterval(handle);
document.getElementById("box").style.width="0px";
}else{
document.getElementById("box").style.width=boxW+"px";
}
}







init();



相关推荐