原生js实现toast右下角弹出消息层效果代码
代码语言:html
所属分类:弹出层
代码描述:原生js实现toast右下角弹出消息层效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
:root {
--page-bg: #333;
--bg-error: 356deg;
--bg-success: 118deg;
--bg-warning: 56deg;
--bg-button: 0deg;
}
@media (prefers-color-scheme: light) {
:root {
--page-bg: linear-gradient(to right, #fcf0c1, #ffcec1);
--bg-error: 356deg;
--bg-success: 118deg;
--bg-warning: 56deg;
--bg-button: 140deg;
}
}
.toast {
display: grid;
grid-template-rows: 54px;
transition: grid-template-rows 250ms ease-in-out;
}
.toast[data-type="error"] {
--bg-current: var(--bg-error);
}
.toast[data-type="success"] {
--bg-current: var(--bg-success);
}
.toast[data-type="warning"] {
--bg-current: var(--bg-warning);
& svg path {
fill: currentColor;
stroke: none;
}
}
.toast_inner {
height: 54px;
display: flex;
align-items: center;
gap: 12px;
padding: 12px 16px;
border: 1px solid #000;
border-radius: 8px;
background-color: hsl(var(--bg-current) 70% 45% / 0.2);
@media (prefers-color-scheme: light) {
background-color: hsl(var(--bg-current) 50% 55% / 0.6);
}
box-shadow: 4px 4px 0px 2px hsl(var(--bg-current) 30% 10% / 0.3);
color: whitesmoke;
transition: transform 350ms ease-in, opacity 350ms ease-in;
overflow: hidden;
& .toast_icon {
color: hsl(var(--bg-current) 86% 45%);
@media (prefers-color-scheme: light) {
color: hsl(var(--bg-current) 96% 65%);
}
}
}
.toast_inner.toast_inner_out {
transform: translateX(20%) scaleY(0);
}
.toast.toast_out {
grid-template-rows: 0px;
}
.toast_icon {
display: flex;
align-items: center;
& svg {
display: block;
width: 28px;
height: 28px;
& path {
stroke: currentColor;
}
}
}
.toast_text {
display: block;
flex: 1 0 auto;
color: hsl(var(--bg-current) 85% 85%);
font-family: "Roboto Mono", monospace;
font-size: 13px;
white-space: nowrap;
overflow: hidden;
@media (prefers-color-scheme: light) {
color: hsl(var(--bg-current) 30% 25%);
}
}
.toast_close {
width: 24px;
height: 24px;
padding: 0;
background.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0