TweenLite+CSSPlugin实现彩色文字字母一个一个弹出动画效果代码

代码语言:html

所属分类:动画

代码描述:TweenLite+CSSPlugin实现彩色文字字母一个一个弹出动画效果代码,可在底部input框输入新的字母文字。

代码标签: TweenLite CSSPlugin 彩色 文字 字母 弹出 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">

    <link href="https://fonts.googleapis.com/css?family=Rubik+Mono+One" rel="stylesheet">
    <style>
        html, body {
      width: 100%;
      height: 100%;
      overflow: hidden;
      font-family: 'Rubik Mono One', sans-serif;
      background: #22292C;
    }
    
    svg {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0px;
      left: 0px;
      z-index: 0;
    }
    
    .input {
      position: absolute;
      z-index: 1;
      bottom: 0px;
      font-size: 20px;
      text-align: center;
      left: 50%;
      transform: translateX(-50%);
      font-family: helvetica, sans-serif;
      bottom: 20px;
      background: none;
      border: 1px solid #ddd;
      color: #eee;
    }
    
    .text, .offscreen-text {
      width: 100%;
      top: 50%;
      transform: translateY(-50%);
      display: block;
      position: absolute;
      margin: 0;
    }
    
    .offscreen-text {
      text-align: center;
      top: -9999px;
    }
    
    .text span {
      position: absolute;
    }
    </style>

</head>

<body>
    <!-- partial:index.partial.html -->
    <p id="offscreen-text" class="offscreen-text"></p>
    <p id="text" class="text"></p>

    <svg id="svg">
</svg>

    <input type="text" class="input" id="input" />
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/CSSPlugin.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/EasePack.1.20.3.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenLite.js"></script>
    <script>
        const selectSVG = id => {
  const el = document.getElementById(id);
  return new SVGElement(el);
};

const createSVG = type => {
  const el = document.createElementNS('http://www.w3.org/2000/svg', type);
  return new SVGElement(el);
};

class SVGElement {
  constructor(element) {
    this.element = element;
  }

  set(attributeName, value) {
    this.element.setAttribute(attributeName, value);
  }

  style(property, value) {
    this.element.style[property] = value;
  }}


const colors = [
{ main: '#FBDB4A', shades: ['#FAE073', '#FCE790', '#FADD65', '#E4C650'] },
{ main: '#F3934A', shades: ['#F7B989', '#F9CDAA', '#DD8644', '#F39C59'] },
{ main: '#EB547D', shades: ['#EE7293', '#F191AB', '#D64D72', '#C04567'] },
{ main: '#9F6AA7', shades: ['#B084B6', '#C19FC7', '#916198', '#82588A'] },
{ main: '#5476B3', shades: ['#6382B9', '#829BC7', '#4D6CA3', '#3E5782'] },
{ main: '#2BB19B', shades: ['#4DBFAD', '#73CDBF', '#27A18D', '#1F8171'] },
{ main: '#70B984', shades: ['#7FBE90', '#98CBA6', '#68A87A', '#5E976E'] }];

const svg = selectSVG('svg');
const text = document.getElementById('text');
const offscreenText = document.getElementById('offscreen-text');
const input = document.getElementById('input');
let width = window.innerWidth;
let height = window.innerHeight;
let textSize = 0;
let textCenter = 0;
const letters = [];
const prompt = ['b', 'f', 'w', '.', 'w', 'i', 'k', 'i'];
let runPrompt = true;

const resizePage = () => {
  width = window.innerWidth;
  height = window.innerHeight;
  svg.set('height', height);
  svg.set('width', width);
  svg.set('viewBox', `0 0 ${width} ${height}`);
  resizeLetters();
};

const resizeLetters = () => {
  textSize = width / (letters.length + 2);
  if (textSize > 100) textSize = 100;
  text.style.fontSize = `${textSize}px`;
  text.style.height = `${textSize}px`;
  text.style.lineHeight = `${textSize}px`;
  offscreenText.style.fontSize = `${textSize}px`;
  const textRect = text.getBoundingClientRect();
  textCenter = textRect.top + textRect.height / 2;
  positionLetters();
};

const positionLetters = () => {
  letters.forEach(letter => {
    const timing = letter.shift ? 0.1 : 0;
    TweenLite.to(letter.onScreen, timing, { x: letter.offScreen.offsetLeft + 'px', ease: Power3.easeInOut });
    letter.shift = true;
  });
};

const animateLetterIn = letter => {
  const.........完整代码请登录后点击上方下载按钮下载查看

网友评论0