div+css原生实现图文堆叠堆积幻灯片点击切换效果代码
代码语言:html
所属分类:幻灯片
代码描述:div+css原生实现图文堆叠堆积幻灯片点击切换效果代码
代码标签: div css 原生 图文 堆叠 堆积 幻灯片 点击 切换
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet"> <style> /* register these two so they can be transitioned */ /* index of previous top item during the animation * after another has been selected */ @property --p { syntax: "<number>"; initial-value: 0; inherits: true; } /* animated index of top item from previous to current */ @property --v { syntax: "<number>"; initial-value: 0; inherits: true; } * { margin: 0; } /* poor man's reset */ /* grid everything! */ html, body, section, article, button { display: grid; } /* full viewport height container for stack section */ html { min-height: 100%; } body { background: #070410; } section { /* set previous top item index to current top index * 0s duration delayed transition ensures switch happens * after the switching top item transtion */ --p: var(--k); /* set previous top item index to current top index * a transition ensures switch doesn't happen instantly */ --v: var(--k); /* difference between current & previous top item indices * 0 if not during animation, * 1 during animation not between two ends, * n - 1 > 1 (if n > 2) during animation from one end to another */ --ini: abs(var(--k) - var(--p)); /* animation from one end of the n > 2 length list to another? * 0 if no, 1 if yes */ --end: clamp(0, var(--ini) - 1, 1); /* absolute value of difference between animated & previous top index */ --abs: abs(var(--v) - var(--p)); /* animation progress as a decimal value */ --dif: calc(var(--abs)/(1 - var(--end) + var(--end)*(var(--n) - 1))); /* direction we're going in given by * sign of difference between current & previous top item indices * -1 backwards, 1 forwards, 0 no animation */ --dir: sign(var(--k) - var(--p)); /* bit form of direction: 0 backwards, 1 forwards */ --bit: calc(.5*(1 + (1 - 2*var(--end))*var(--dir))); /* bigger space between the two columns (image stack & all else) */ grid-gap: 0.5em 4em; grid-template: repeat(2, max-content) 1fr max-content/max-content 1fr; place-self: center; color: #f1f5f9; font: 1em poppins, sans-serif; counter-reset: k calc(1 + var(--k)) n var(--n); /* transition previous & animated top item indices * so they don't change instantly like the current one */ transition: --p 0s 0.8s, --v 0.8s; /* counter & binomial name faded */ /* this ridiculousness needed for Chrome without flag */ /* for reference * https://css-tricks.com/using-absolute-value-sign-rounding-and-modulo-in-css-today/ */ } section::before, section em { color: RGB(from currentColor r g b/0.6); } section::before {.........完整代码请登录后点击上方下载按钮下载查看
网友评论0