網站首頁 編程語言 正文
這個可能更多的就是css樣式上的書寫,js上很簡單就是個狀態的控制
封裝一個 FloatTop.jsx
import "./index.scss"
const FloatTop = ({ children, showMask, handleChange}) => {
return (
<div className="float-container">
<div className="content">
<div className={`slot-content ${showMask && ' show'}`}>
{ children }
</div>
</div>
<div onClick={handleChange} className={`mask ${showMask && 'show'}`}></div>
</div>
)
}
export default FloatTop;
index.scss
.float-container {
position: fixed;
width: 100%;
left: 0;
top: 0;
.content {
position: relative;
height: 0;
z-index: 3;
.slot-content {
position: absolute;
width: 100%;
box-sizing: border-box;
bottom: 0;
background-color: white;
border-radius: 0 0 10px 10px;
overflow: hidden;
transition: transform 0.2s ease-in-out;
z-index: 9;
padding: 20px;
transform: translateY(0%);
&.show {
transform: translateY(100%);
}
}
}
.mask {
position: absolute;
z-index: 1;
width: 100%;
height: 100vh;
top: 0px;
transition: all 0.2s linear;
background-color: rgba(0, 0, 0, 0);
display: none;
&.show {
background-color: rgba(0, 0, 0, 0.5);
pointer-events: inherit;
display: block;
}
}
}
然后就是引用和使用了
import { useState } from "react"
import "./App.scss"
import FloatTop from './components/FloatTop';
function App() {
const [status, setStatus] = useState(false)
return (
<div className="App">
<FloatTop showMask={status} handleChange={() => setStatus(false)}>
<div className="test-sass">hello world</div>
</FloatTop>
<button onClick={() => setStatus(status => !status)}>顯示</button>
</div>
);
}
export default App;
這個 也可以在小程序中使用 原理差不多
關注我 持續更新前端知識
原文鏈接:https://yunchong.blog.csdn.net/article/details/122218174
相關推薦
- 2022-09-20 關于go-zero單體服務使用泛型簡化注冊Handler路由的問題_Golang
- 2022-02-21 MyBatis There is no getter for property named ‘xxx
- 2022-08-19 python中的函數和變量的用法
- 2022-10-22 Go語言數據結構之單鏈表的實例詳解_Golang
- 2023-02-10 Redis如何正確關閉和開啟持久化_Redis
- 2023-01-12 Python讀取及保存mat文件的注意事項說明_python
- 2022-09-22 transition transform屬性造成文字抖動及模糊的解決方法
- 2022-07-17 Redis內部數據結構Dict的實現方法_Redis
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支