javascript實(shí)現(xiàn)輪顯新聞標(biāo)題鏈接
用兩個div嵌套鏈接文字,最外面的div設(shè)置 overflow:hidden,并用js動態(tài)控制它的width,實(shí)現(xiàn)伸展與收縮。
<!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 = "世界上第一個比空氣重的航空器是什么?|手機(jī)泄密!你以為已經(jīng)刪掉的照片,就是這么被找回泄露的!|M2 iPad Pro 真的要來了!|不知道,現(xiàn)在還有多少人在意小屏手機(jī)呢?";
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>
相關(guān)文章
JavaScript去掉數(shù)組重復(fù)項(xiàng)的方法分析【測試可用】
這篇文章主要介紹了JavaScript去掉數(shù)組重復(fù)項(xiàng)的方法,結(jié)合實(shí)例形式分析了javascript使用object特性實(shí)現(xiàn)數(shù)組去除重復(fù)項(xiàng)功能的相關(guān)操作技巧,需要的朋友可以參考下2018-07-07js驗(yàn)證IP及子網(wǎng)掩碼的合法性有效性示例
這篇文章主要介紹了js驗(yàn)證IP及子網(wǎng)掩碼的有效性,需要的朋友可以參考下2014-04-04詳解JavaScript如何實(shí)現(xiàn)并發(fā)控制的Promise隊(duì)列調(diào)度器
Promise是JavaScript中一種處理異步操作的技術(shù),提供了一種更優(yōu)雅的方式來處理并發(fā)任務(wù)和串行化操作,本文主要介紹了實(shí)現(xiàn)并發(fā)控制的Promise隊(duì)列調(diào)度器的方法,需要的可以參考一下2023-07-07JavaScript數(shù)組去重的五種方法及其他細(xì)節(jié)和拓展
JavaScript數(shù)組去重這個問題,經(jīng)常出現(xiàn)在面試題中,下面這篇文章主要給大家介紹了關(guān)于JavaScript數(shù)組去重的五種方法及其他細(xì)節(jié)和拓展的相關(guān)資料,文中通過實(shí)例代碼以及圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12JavaScript實(shí)現(xiàn)ASC轉(zhuǎn)漢字及漢字轉(zhuǎn)ASC的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)ASC轉(zhuǎn)漢字及漢字轉(zhuǎn)ASC的方法,涉及JavaScript編碼轉(zhuǎn)換的相關(guān)技巧,需要的朋友可以參考下2016-01-01