js编程之轮显新闻标题链接实例代码

来源:爱站网时间:2022-12-19编辑:网友分享
今天给朋友们讲解下js编程之轮显新闻标题链接实例代码是详细内容,如果需要这篇文章代码的朋友,可以随时来复制粘贴使用,希望爱站技术频道频道小编提供的资料对你有用处。

用两个div嵌套链接文字,最外面的div设置 overflow:hidden,并用js动态控制它的width,实现伸展与收缩。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>新闻轮显的demo</title>
<style type="text/css">
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*/}
</style>
<script type="text/javascript">
var handle;
var handle2;
var boxW=0;
var titleNum=0;
function init(){
 var newsTitles = "世界上第一个比空气重的航空器是什么?|手机泄密!你以为已经删掉的照片,就是这么被找回泄露的!|M2 iPad Pro 真的要来了!|不知道,现在还有多少人在意小屏手机呢?";
 var newsLinks = "http://news.sina.com.cn|http://news.sina.com.cn/c/2006-09-02/093410901015.shtml|https://new.qq.com/rain/a/20221008V06OGZ00|https://new.qq.com/rain/a/20221016A06DR500|https://new.qq.com/rain/a/20221012A06FF100";
 document.getElementById("box").style.width = "400px";
 document.getElementById("title").innerHTML = "<a target=’_blank’ href=’"+newsLinks.split("|")[titleNum]+"’>"+newsTitles.split("|")[titleNum]+"</a>";
 //setTimeout("decreaseBoxW();",1500);
 titleNum++;
 setInterval("innerTitle(’"+newsTitles+"’,’"+newsLinks+"’)",3100);
}
function innerTitle(titles,links){
 var t = titles.split("|");
 var a = links.split("|");
 if (!t[titleNum])
 titleNum=0;
 document.getElementById("box").style.width = "0px";
 document.getElementById("title").innerHTML = "<a target=’_blank’ href=’"+a[titleNum]+"’>"+t[titleNum]+"</a>";
 handle2 = setInterval("increaseBoxW()",1);//展开
 titleNum++;
}
function increaseBoxW(){
 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";
 }
}
function decreaseBoxW(){
 handle = setInterval("decreaseBoxW2()",4)
}
function decreaseBoxW2(){
 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";
 }
}
</script>
</head>
<body>
<div id="box">
 <div id="title"></div>
</div>
<script type="text/javascript">
init();
</script>
</body>
</html>

js编程之轮显新闻标题链接实例代码相信朋友们都看完了吧,密密麻麻的代码是不是有点眼花缭乱呢,如果不清楚,随时都可以来联系小编解答,希望你们喜欢本网站平台。

上一篇:js中的Array对象详细内容

下一篇:js编程中怎么隐藏红叉叉

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载