js实现文本打字一行一行出现动画效果代码
代码语言:html
所属分类:动画
代码描述:js实现文本打字一行一行出现动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Unica+One'> <style> * { box-sizing: border-box; } html, body { height: 100%; margin: 0; font-family: "Unica One", sans-serif; background: #111; } .container { display: flex; align-items: center; justify-content: center; height: 100%; padding: 5rem; } .heading { color: #eee; font-size: 5rem; font-weight: 300; text-transform: uppercase; } </style> </head> <body > <div class="container"> <h1 class="heading" data-target-resolver></h1> </div> <script > const resolver = { resolve: function resolve(options, callback) { // The string to resolve const resolveString = options.resolveString || options.element.getAttribute('data-target-resolver'); const combinedOptions = Object.assign({}, options, { resolveString: resolveString }); function getRandomInteger(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }; function randomCharacter(characters) { return characters[getRandomInteger(0, characters.length - 1)]; }; function doRandomiserEffect(options, callback) { const characters = options.characters; const timeout = options.timeout; const element = options.element; const partialString = options.partialString; let iterations = options.iterations; setTimeout(() => { if (iterations >= 0) { const nextOptions = Object.assign({}, options, { iterations: iterations - 1 }); // Ensures partialString without the random character as the final state. if (iterations === 0) { element.textContent = partialString; } else { // Replaces the last character of partialString with a random character element.textContent = partialString.substring(0, partialString.length - 1) + randomCharacter(characters); } doRandomiserEffect(nextOptions, callback); } else if (typeof callback === "function") { callback(); } }, options.timeout); }; function doResolverEffect(options, callback) { const resolveString = options.resolveString; const characters = options.characters; const offset = options.offset; const partialString = resolveString.substring(0, offset); const combinedOptions = Object.assign({}, options, { partialString: partialString }); doRandomiserEffect(combinedOptions, () => { const nextOptio.........完整代码请登录后点击上方下载按钮下载查看
网友评论0