国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Problème d'animation Apple utilisant React et CSS en ligne
P粉729436537
P粉729436537 2024-01-10 17:08:30
0
1
539

J'essaie de recréer cette animation dans React en utilisant HTML et CSS, en utilisant des styles en ligne et TypeScript. Je crée un objet avec des informations de style et je le référence dans l'attribut style. Ci-dessous le code. Cela ne fonctionne pas, je ne suis pas s?r de ce que je fais de mal, je soup?onne que les styles ne sont pas définis et référencés correctement??

Voici l'exemple Codepen original que j'ai essayé de réécrire?: Apple Animation

Voici mon code

import React from 'react';

const styles = {
    
    '@keyframes showTopText': {
        '0%': { transform: 'translate3d(0, 100%, 0)' },
        '40%, 60%': { transform: 'translate3d(0, 50%, 0)' },
        '100%': { transform: 'translate3d(0, 0, 0)' },
    },
    '@keyframes showBottomText': {
        '0%': { transform: 'translate3d(0, -100%, 0)' },
        '100%': { transform: 'translate3d(0, 0, 0)' },
    },

    animatedTitle: {
        color: '#222',
        fontFamily: 'Roboto, Arial, sans-serif',
        height: '90vmin',
        left: '50%',
        top: '50%',
        transform: 'translate(-50%, -50%)',
        width: '90vmin',
    },
    'animatedTitle > div': {
        height: '50%',
        overflow: 'hidden',
        position: 'absolute',
        width: '100%',
    },
    'animatedTitle > div div': {
        fontSize: '12vmin',
        padding: '2vmin 0',
        position: 'absolute',
    },
    'animatedTitle > div div span': {
        display: 'block',
    },
    'animated-title > div.text-top': {
        borderBottom: '1vmin solid #000',
        top: 0,
    },
    'animatedTitle > div.text-top div': {
        animation: 'showTopText 1s',
        animationDelay: '0.5s',
        animationFillMode: 'forwards',
        bottom: 0,
        transform: 'translate(0, 100%)',
    },
    'animatedTitle > div.text-top div span:first-child': {
        color: '#767676',
    },
    'animatedTitle > div.text-bottom': {
        bottom: 0,
    },
    'animatedTitle > div.text-bottom div': {
        animation: 'showBottomText 0.5s',
        animationDelay: '1.75s',
        animationFillMode: 'forwards',
        top: 0,
        transform: 'translate(0, -100%)',
    },
};

function Design() {
    return (
        <div style={styles.animatedTitle}>
            <div style={styles['animatedTitle > div.text-top div']}>
                <div>
                    <span>mimicking</span>
                    <span>apple's design</span>
                </div>
            </div>
            <div style={styles['animatedTitle > div.text-bottom']}>
                <div>for the win!</div>
            </div>
        </div>
    );
}

export { Design };

P粉729436537
P粉729436537

répondre à tous(1)
P粉115840076

Vous pouvez essayer d'utiliser styled-components 來使您的組件更靈活和兼容。我使用 styled-components qui reproduit l'exemple codepen et facilite son extension.

Par conséquent, TopAnimateBlock et BottomAnimateBlock ont tous deux l'attribut TopAnimateBlockBottomAnimateBlock 都有 numOfLine 屬性,表示塊內(nèi)有多少行。在 BottomAnimateBlock 中的第二個(gè)屬性是 delayTopLine,它應(yīng)該與 TopAnimateBlocknumOfLine, qui indique le nombre de lignes à l'intérieur du bloc. La deuxième propriété de BottomAnimateBlock est delayTopLine

, qui devrait être le même nombre de

numOfLineTextStyle dans TopAnimateBlock car nous devons attendre que la rangée du haut soit jouée. De plus, vous pouvez facilement changer la couleur du texte via l'attribut color de et transmettre la valeur de couleur, HEX color ou rgba()

/

hsla()

.

TexteAnimation.tsx

import styled, { keyframes } from 'styled-components';

const showTopText = keyframes`
  0% { transform: translate3d(0, 100% , 0); }
  40%, 60% { transform: translate3d(0, 50%, 0); }
  100% { transform: translate3d(0, 0, 0); }
`;
const showBottomText = keyframes`
  0% { transform: translate3d(0, -100%, 0); }
  100% { transform: translate3d(0, 0, 0); }
`;

const Section = styled.section`
  width: calc(100% + 10vmin);
  display: flex;
  flex-flow: column;
  padding: 2vmin 0;
  overflow: hidden;
  &:last-child {
    border-top: 1vmin solid white;
  }
`;

const Block = styled.div<{ numOfLine: number }>`
  position: relative;
`;
const TopAnimateBlock = styled(Block)`
  animation: ${showTopText} calc(0.5s * ${props => props.numOfLine}) forwards;
  animation-delay: 0.5s;
  transform: translateY(calc(100% * ${props => props.numOfLine}));
`;
const BottomAnimateBlock = styled(Block)<{ delayTopLine: number }>`
  animation: ${showBottomText} calc(0.5s * ${props => props.numOfLine}) forwards;
  animation-delay: calc(0.7s * ${props => props.delayTopLine});
  transform: translateY(calc(-100% * ${props => props.numOfLine}));
`;

const TextStyle = styled.p<{ color: string }>`
  font-family: Roboto, Arial, sans-serif;
  font-size: 12vmin;
  color: ${props => props.color};
`;

export const TextAnimation = () => {
  return (
    <>
      <Section>
        <TopAnimateBlock numOfLine={2}>
          <TextStyle color="grey">mimicking</TextStyle>
          <TextStyle color="white">apple's design</TextStyle>
        </TopAnimateBlock>
      </Section>
      <Section>
        <BottomAnimateBlock numOfLine={1} delayTopLine={2}>
          <TextStyle color="white">for the win!</TextStyle>
        </BottomAnimateBlock>
      </Section>
    </>
  );
};

  1. Si nous voulons animer 3 lignes au lieu de 2, il suffit d'ajouter/modifier?: TextStyle
  2. Ajouter un nouveau TopAnimateBlock 中將 numOfLine 從2更改為3,在 BottomAnimateBlockcomposant Changement de
  3. numOfLine
  4. de 2 à 3 dans TopAnimateBlock et
  5. delayTopLine
de 2 à 3?? dans BottomAnimateBlock ??Et remplacez l'image clé par le clip suivant?: ?? ??
const showTopText = keyframes`
  0% { transform: translate3d(0, 100% , 0); }
  25%, 40% { transform: translate3d(0, 66%, 0); }
  60%, 75% { transform: translate3d(0, 33%, 0); }
  100% { transform: translate3d(0, 0, 0); }
`;
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal