Created
September 7, 2017 00:51
-
-
Save liuxd/d0f96d62226f95b354dc1301fd689997 to your computer and use it in GitHub Desktop.
title flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>闪烁title</title> | |
</head> | |
<body> | |
<script type="text/javascript" language="javascript"> | |
var flashTitlePlayer = { | |
//开始闪烁。 | |
//@param string $msg | |
start: function(msg) { | |
this.title = document.title; | |
if (!this.action) { | |
try { | |
this.element = document.getElementsByTagName('title')[0]; | |
this.element.innerHTML = this.title; | |
this.action = function(ttl) { | |
this.element.innerHTML = ttl; | |
}; | |
} catch (e) { | |
this.action = function(ttl) { | |
document.title = ttl; | |
} | |
delete this.element; | |
} | |
this.toggleTitle = function() { | |
this.action('【' + this.messages[this.index = this.index == 0 ? 1 : 0] + '】' + this.title); | |
}; | |
} | |
if (typeof msg !== 'string') { | |
msg += ""; | |
} | |
this.messages = [msg]; | |
var n = msg.length; | |
var s = ''; | |
if (this.element) { | |
var num = msg.match(/\w/g); | |
if (num != null) { | |
var n2 = num.length; | |
n -= n2; | |
while (n2 > 0) { | |
s += " "; | |
n2--; | |
} | |
} | |
} | |
while (n > 0) { | |
s += ' '; | |
n--; | |
} | |
; | |
this.messages.push(s); | |
this.index = 0; | |
this.timer = setInterval(function() { | |
flashTitlePlayer.toggleTitle(); | |
}, 1000); | |
}, | |
//停止闪烁 | |
stop: function() { | |
if (this.timer) { | |
clearInterval(this.timer); | |
this.action(this.title); | |
delete this.timer; | |
delete this.messages; | |
} | |
} | |
}; | |
flashTitlePlayer.start(123); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment