JavaScript 实现标题滚动效果
作者:互联网
JavaScript 实现标题滚动效果
实现步骤
- 定义需要滚动的标题字符串
let title = 'Nothing is impossible for a willing mind'
- 定义实现标题滚动的函数
function titleChange () {
const keywords = title.split('') // 将标题转为字符串数组
const firstChar = keywords.shift() // 取出标题中第一个字符
keywords.push(firstChar)
title = keywords.join('')
document.title = title
}
- 开启定时器
setInterval(fn, delay)
完整代码
let title = 'Nothing is impossible for a willing mind'
function titleChange () {
const keywords = title.split('')
const firstChar = keywords.shift()
keywords.push(firstChar)
title = keywords.join('')
document.title = title
}
setInterval(titleChange, 500)
标签:滚动,title,JavaScript,标题,keywords,const,titleChange,firstChar 来源: https://blog.csdn.net/m0_57835615/article/details/120602966