网站首页 > 教程分享 正文
看
了以前书里面的一个例子;没有什么太大的技术含量,大致就是运用递归,然后定义两个定时器单个文字和单行文字。
效果图:
代码:
<!DOCTYPE html> <html> <head> <title>测试</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <style> body { font-weight: bold; } a { text-decoration:none; letter-spacing:2px; } </style> </head> <body> 松花水月最新微博消息:<a id="HotNews" target="_blank"></a> <script type="text/javascript"> let newsTime = 2000 // 每条微博的停留时间 let textTime = 200 // 微博文字出现等待时间, 越小越快 let newsi = 0 let txti = 0 let txttimer = null let newstimer = null let newstitle = [ '健康是生命的本钱', '关心身体,就是关心自己', '去西藏旅游了', '大雨倾盆,很大呀' ] let newshref = ['#','#','#','#'] // 微博链接 function shownew () { let endStr = '_' hwnewstr = newstitle[newsi] newslink = newshref[newsi] if (txti === (hwnewstr.length -1)) endStr = '' if (txti >= hwnewstr.length) { clearInterval(txttimer) clearInterval(newstimer) newsi ++ if (newsi >= newstitle.length) newsi = 0 newstimer = setInterval('shownew()', newsTime) txti = 0 return } clearInterval(txttimer) HotNews.href = newslink HotNews.innerHTML = hwnewstr.substring(0, txti+1) + endStr txti++ txttimer = setInterval('shownew()', textTime) } shownew() </script> </body> </html>
- 上一篇: Vue实战088:简单的验证码倒计时功能实现
- 下一篇: 导航栏案例:用到缓动函数(缓动类型)
猜你喜欢
- 2024-09-10 JavaScript 定时器和延时器(js定时器执行顺序)
- 2024-09-10 彻底搞懂HTTP协议 - 天天造轮子(http协议的工作原理)
- 2024-09-10 导航栏案例:用到缓动函数(缓动类型)
- 2024-09-10 Vue实战088:简单的验证码倒计时功能实现
- 2024-09-10 微信小程序开发(2):猜拳游戏全过程详解
- 2024-09-10 用多了各种组件库的你还会用原生JS写轮播图吗?
- 2024-09-10 canvas绘制图片并实现一个图片放大器
- 2024-09-10 Window 对象(window对象的子对象)
- 2024-09-10 微信刷屏的「给我一面国旗」怎么才能做到,技术原理是什么?
- 2024-09-10 「JavaScript-4」 定时器(定时器软件)
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- css导航条 (66)
- sqlinsert (63)
- js提交表单 (60)
- param (62)
- parentelement (65)
- jquery分享 (62)
- check约束 (64)
- curl_init (68)
- sql if语句 (69)
- import (66)
- chmod文件夹 (71)
- clearinterval (71)
- pythonrange (62)
- 数组长度 (61)
- javafx (59)
- 全局消息钩子 (64)
- sort排序 (62)
- jdbc (69)
- php网页源码 (59)
- assert h (69)
- httpclientjar (60)
- postgresql conf (59)
- winform开发 (59)
- mysql数字类型 (71)
- drawimage (61)
本文暂时没有评论,来添加一个吧(●'◡'●)