Last active
January 11, 2018 03:08
-
-
Save flxxyz/a54f8be70e7b39831dd2f8bb27813fac to your computer and use it in GitHub Desktop.
预定义字符串,随机打乱成新字符串滚动,控制运行时间
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
function str_rand_scroll(el, time, str) { | |
try { | |
if (el === undefined) throw '没有传入变量el'; | |
try { | |
if (time === undefined) throw '没有传入变量time'; | |
try { | |
if (str === undefined) { | |
// var str = '一乙二十丁厂七卜八人入儿匕几九刁了刀力乃又三干于亏工土士才下寸大丈与万上小口山巾千乞川亿个夕久么勺凡丸及广亡门丫义之尸己已巳弓子卫也女刃飞习叉马乡丰王开井天夫元无云专丐扎艺木五支厅不犬太区历歹友尤匹车巨牙屯戈比互切瓦止少曰日中贝冈内水见午牛手气毛壬升夭长仁什片仆化仇币仍仅斤爪反介父从仑今凶分乏公仓月氏勿欠风丹匀乌勾凤六文亢方火为斗忆计订户认冗讥心尺引丑巴孔队办以允予邓劝双书幻玉刊未末示击打巧正扑卉扒功扔去甘世艾古节本术可丙左厉石右布夯戊龙平灭轧东卡北占凸卢业旧帅归旦目且叶甲申叮电号田由只叭史央兄叽叼叫叩叨'; | |
var str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+' | |
} | |
str = str.split(''); | |
var text = el.innerHTML.split(''); | |
var s = time; // 运行时间 | |
var t = text.concat(); // 备份文字,以免引用导致直接修改引用 | |
var b = []; // 待还原数组 | |
var n = 0; | |
console.time('start'); | |
var timer = setInterval(function () { | |
var a = []; // 打乱数组 | |
var p = Math.ceil(s / ((text.length * 5.5) - (s / 1000))); // 运行时间概率 | |
if ((n % p) === 1) { | |
b.unshift(t[t.length - 1]); // 填入 | |
t.pop(); | |
} | |
// console.log('b.length=' + b.length + ', text.length=' + text) | |
if (b.length === text.length) { | |
clearInterval(timer); | |
console.timeEnd('start'); | |
} | |
for (var i = 0; i < t.length; i++) { | |
var index = Math.ceil(Math.random() * (str.length - 1)); | |
a.push(str[index]); | |
} | |
el.innerHTML = a.join('') + b.join(''); | |
n++; | |
}, 5) | |
} catch (e) {log('没有传入变量str');return} | |
} catch (e) {log('没有传入变量time');return} | |
} catch (e) {log('没有传入变量el');return} | |
function log(a) {try {console.log(a)} catch (e) {console.log('没有任何字符串');return}} | |
} |
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 lang="zh"> | |
<meta charset="UTF-8"> | |
<title>Download - 冯小贤</title> | |
<style>html,body{width: 100%;height: 100%; overflow: hidden;}body {background: rgba(0,0,0,.85);} h1{font-size: 10em;font-weight: normal;color: lawngreen;text-align: right;padding-top: 15%;padding-right: 10%}</style> | |
<body> | |
<h1>Download</h1> | |
</body> | |
<script> | |
(function () { | |
var h = document.querySelector('h1'); | |
str_rand_scroll(h, 2000, '0123456789'); | |
setTimeout(function () { | |
h.innerHTML = '你盯着我看了这么长时间,想干♂嘛?' | |
}, 100000) | |
})() | |
</script> | |
<script src="./function.js"></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment