欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

如何在Next.js中將帶有自定義CSS屬性和動畫的代碼轉換為樣式化組件

江奕云2年前7瀏覽0評論

我發現了一個美麗的邊框漸變,有著驚人的旋轉發光效果。我正在使用next.js和styled-components。我不確定如何正確地將這個純CSS轉換成樣式化的組件。我所指的代碼是:

@property --rotate {
  syntax: "<angle>";
  initial-value: 132deg;
  inherits: false;
}

@keyframes SpinAnimation{
  0% {
    --rotate: 0deg;
  }
  100% {
    --rotate: 360deg;
  }
}

我一直在尋找如何將這些代碼轉換成樣式化組件的解決方案,但是經過一個小時的研究,我沒有得到任何積極的結果。我的首選資源ChatGPT一直建議對SpinAnimation使用Transform屬性,它的行為與我預期的略有不同。

原始CSS

@property --rotate {
  syntax: "<angle>";
  initial-value: 132deg;
  inherits: false;
}

:root {
  --card-height: 65vh;
  --card-width: calc(var(--card-height) / 1.5);
}


body {
  min-height: 100vh;
  background: #212534;
  display: flex;
  align-items: center;
  flex-direction: column;
  padding-top: 2rem;
  padding-bottom: 2rem;
  box-sizing: border-box;
}


.card {
  background: #191c29;
  width: var(--card-width);
  height: var(--card-height);
  padding: 3px;
  position: relative;
  border-radius: 6px;
  justify-content: center;
  align-items: center;
  text-align: center;
  display: flex;
  font-size: 1.5em;
  color: rgb(88 199 250 / 0%);
  cursor: pointer;
  font-family: cursive;
}

.card:hover {
  color: rgb(88 199 250 / 100%);
  transition: color 1s;
}
.card:hover:before, .card:hover:after {
  animation: none;
  opacity: 0;
}


.card::before {
  content: "";
  width: 104%;
  height: 102%;
  border-radius: 8px;
  background-image: linear-gradient(
    var(--rotate)
    , #5ddcff, #3c67e3 43%, #4e00c2);
    position: absolute;
    z-index: -1;
    top: -1%;
    left: -2%;
    animation: spin 2.5s linear infinite;
}

.card::after {
  position: absolute;
  content: "";
  top: calc(var(--card-height) / 6);
  left: 0;
  right: 0;
  z-index: -1;
  height: 100%;
  width: 100%;
  margin: 0 auto;
  transform: scale(0.8);
  filter: blur(calc(var(--card-height) / 6));
  background-image: linear-gradient(
    var(--rotate)
    , #5ddcff, #3c67e3 43%, #4e00c2);
    opacity: 1;
  transition: opacity .5s;
  animation: spin 2.5s linear infinite;
}

@keyframes spin {
  0% {
    --rotate: 0deg;
  }
  100% {
    --rotate: 360deg;
  }
}

a {
  color: #212534;
  text-decoration: none;
  font-family: sans-serif;
  font-weight: bold;
  margin-top: 2rem;
}

我的樣式組件

const rotateZero = '';
const rotateAround = '';

const SpinAnimation = keyframes`
  0% {
    ${rotateZero}: 0deg;
  }
  100% {
    ${rotateAround}: 360deg;
  }
`;

const height = '30vh';
const width = `calc(${height} / 1.5)`;
const rotate = '132deg';

export const TechItem = styled.div`
  @media (min-width: 768px) {
    position: absolute;
    top: ${(props) => props.top};
    left: ${(props) => props.left};
  }

  background: #191c29;
  width: ${width};
  height: ${height};
  padding: 3px;
  position: relative;
  border-radius: 6px;
  justify-content: center;
  align-items: center;
  text-align: center;
  display: flex;
  font-size: 1.5em;
  color: rgb(88 199 250 / 0%);
  cursor: pointer;
  font-family: cursive;

  &:hover {
    color: rgb(88 199 250 / 100%);
    transition: color 1s;
  }

  &:hover:before,
  &:hover:after {
    animation: none;
    opacity: 0;
  }

  &::before,
  &::after {
    content: '';
    width: 104%;
    height: 102%;
    border-radius: 8px;
    position: absolute;
    z-index: -1;
    top: -1%;
    left: -2%;
    opacity: 1;
    transition: opacity 0.5s;
  }

  &::before {
    background-image: linear-gradient(${rotate}, #5ddcff, #3c67e3 43%, #4e00c2);
    animation: ${SpinAnimation} 2.5s linear infinite;
  }

  &::after {
    top: calc(${height} / 6);
    transform: scale(0.8);
    filter: blur(calc(${height} / 6));
    background-image: linear-gradient(${rotate}, #5ddcff, #3c67e3 43%, #4e00c2);
    animation: ${SpinAnimation} 2.5s linear infinite;
  }
`;