分類
<link type="text/css" href="css/style.css" rel="stylesheet" />
<script src="js/jquery-3.3.1.min.js"></script>
<div class="loading">Loading</div>
<script type="text/javascript">
$(document).ready(function() {
let loading = $('.loading').wrapInner('<div></div>'),
min = 20,
max = 70,
minMove = 10,
maxMove = 20;
startAnimation(loading);
loading.on('animationend webkitAnimationEnd oAnimationEnd', 'span:last-child', e => {
startAnimation(loading);
});
//設(shè)置CSS變量并根據(jù)需要生成跨距
function setCSSVars(elem, min, max, minMove, maxMove) {
let width = Math.ceil(elem.width()),
text = elem.text();
for(let i = 1; i < width; i++) {
let num = Math.floor(Math.random() * (max - min + 1)) + min,
numMove = Math.floor(Math.random() * (maxMove - minMove + 1)) + minMove,
dir = (i % 2 == 0) ? 1 : -1,
spanCurrent = elem.find('span:eq(' + i + ')'),
span = spanCurrent.length ? spanCurrent : $('<span />');
span.css({
'--x': i - 1 + 'px',
'--move-y': num * dir + 'px',
'--move-y-s': ((i % 2 == 0) ? num * dir - numMove : num * dir + numMove) + 'px',
'--delay': i * 10 + 'ms'
});
if(!spanCurrent.length) {
elem.append(span.text(text));
}
}
}
//開(kāi)始動(dòng)畫(huà)
function startAnimation(elem) {
elem.removeClass('start');
setCSSVars(elem, min, max, minMove, maxMove);
void elem[0].offsetWidth;
elem.addClass('start');
}
});
</script>
1. 本站所有素材(未指定商用),僅限學(xué)習(xí)交流。
2. 會(huì)員在本站下載的原創(chuàng)商用和VIP素材后,只擁有使用權(quán),著作權(quán)歸原作者及17素材網(wǎng)所有。
3. 原創(chuàng)商用和VIP素材,未經(jīng)合法授權(quán),請(qǐng)勿用于商業(yè)用途,會(huì)員不得以任何形式發(fā)布、傳播、復(fù)制、轉(zhuǎn)售該素材,否則一律封號(hào)處理。
4. 本平臺(tái)織夢(mèng)模板僅展示和個(gè)人非盈利用途,織夢(mèng)系統(tǒng)商業(yè)用途請(qǐng)預(yù)先授權(quán)。