以代码形式实现过程分析:
<html>
<head>
<title>打字效果</title>
<meta http-equiv="Content-Type" Content="text/html;charset=gb2312" />
<style type="text/css">
body{
font-size:14px;
font-color:#purple;
font-weight:bolder;
}
</style>
</head>
<body>
最新内容: <a id = "Hotnews" href="" target="_blank"> </a>
<script language="javascript">
var NewsTime = 2000; //每条信息完整出现后停留时间
var TextTime = 100; //每条信息中的字出现的间隔时间
var newsi = 0;
var txti = 0;
var txttimer; //调用setInterval的返回值,用于取消对函数的周期性执行
var newstimer;
var newstitle = new Array(); //以数组形式保存每个信息的标题
var newshref = new Array(); //以数组形式保存信息标题的链接
newstitle[0] = "欢迎来到我的博客"; //显示在网页上的文字内容和对应的链接
newshref[0] = "https://www.jb51.net/guihailiuli/";
newstitle[1] = "https://www.jb51.net/guihailiuli/";
newshref[1] = "https://www.jb51.net/guihailiuli/";
newstitle[2] = "博客园欢迎你哦";
newshref[2] = "https://www.jb51.net";
newstitle[3] = "ByeBye~~";
newshref[3] = "https://www.jb51.net";
function shownew(){
hwnewstr=newstitle[newsi]; //通过newsi传递,依次显示数组中的内容
newslink=newshref[newsi]; //依次显示文字对应的链接
if(txti>=hwnewstr.length){
clearInterval(txttimer); //一旦超过要显示的文字长度,清除对shownew()的周期性调用
clearInterval(newstimer);
newsi++; //显示数组中的下一个
if(newsi>=newstitle.length){
newsi = 0; //当newsi大于信息标题的数量时,把newsi清零,重新从第一个显示
}
newstimer = setInterval("shownew()",NewsTime); //间隔2000ms后重新调用shownew()
txti = 0;
return;
}
clearInterval(txttimer);
document.getElementById("Hotnews").href = newslink;
document.getElementById("Hotnews").innerHTML = hwnewstr.substring(0,txti+1); //截取字符,从第一个字符到txti+1个字符
txti++; //文字一个个出现
txttimer = setInterval("shownew()",TextTime);
}
shownew();
</script>
</body>
</html>
以上所述就是本文的全部内容了,希望能够给大家学习javascript有些帮助。
标签:
JS,打字
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
内蒙古资源网 Copyright www.nmgbbs.com
暂无“JS实现简单的键盘打字的效果”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。