1 Star 0 Fork 0

lifankohome / MTitle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
MTitle.js 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
lifankohome 提交于 2019-07-28 17:52 . MTitle v0.0.1
/**
* MTitle.js v1.0
* Created by lifanko on 2019/7/28.
* https://gitee.com/lifanko/MTitle
*/
class MTitle {
constructor(title = 'MTitle', space = 1) {
this.mtitle = title;
this.space = space;
this.timer = null;
this.addSpace();
}
newTitle(title = 'MTitle') {
this.mtitle = title;
this.addSpace();
}
newSpace(space = 1) {
this.space = space;
this.addSpace();
}
addSpace() {
let buffer = '';
for (let i = 0; i < this.space; i++) {
buffer += ' ';
}
this.title = this.mtitle + buffer + this.mtitle;
this.length = this.mtitle.length + this.space;
this.index = 0;
}
stop(reset = false) {
if (this.timer !== null) {
clearInterval(this.timer);
this.timer = null;
}
if (reset) {
this.index = 0;
this.move();
}
}
move() {
if (this.index >= this.length) {
this.index = 0;
}
document.title = this.title.substr(this.index++, this.length);
}
start(interval = 1000) {
if (this.timer === null) {
let t = this;
this.timer = setInterval(function () {
t.move();
}, interval);
}
}
}
JavaScript
1
https://gitee.com/lifanko/MTitle.git
git@gitee.com:lifanko/MTitle.git
lifanko
MTitle
MTitle
master

搜索帮助