我试图在样式组件文档中找到一个方法来创建一个循环。例如,我能在样式组件中实现这个scss循环吗?
@for $i from 0 through 20 {
#loadingCheckCircleSVG-#{$i} {
animation: fill-to-white 5000ms;
animation-delay: ($i - 1.5) * 1s;
fill: white;
opacity: 0;
}
}有可能吗?
发布于 2018-10-10 04:04:19
我们目前不支持来自scss的迭代语法。但是,由于样式组件接受JS内插,所以您只需编写一个简单的JS函数来生成所需的CSS并将其放入其中。
import styled, { css } from "styled-components";
function createCSS() {
let styles = '';
for (let i = 0; i < 20; i += 1) {
styles += `
#loadingCheckCircleSVG-${i} {
animation: fill-to-white 5000ms;
animation-delay: ${i - 1.5}s;
fill: white;
opacity: 0;
}
`
}
return css`${styles}`;
}
const Thing = styled.div`
${createCSS()};
`https://stackoverflow.com/questions/52696511
复制相似问题