https://github.com/x-extends/dom-zindex
Web common z-index style management
https://github.com/x-extends/dom-zindex
Last synced: over 1 year ago
JSON representation
Web common z-index style management
- Host: GitHub
- URL: https://github.com/x-extends/dom-zindex
- Owner: x-extends
- License: mit
- Created: 2023-08-02T15:06:30.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-16T08:33:11.000Z (over 1 year ago)
- Last Synced: 2025-03-30T07:02:25.121Z (over 1 year ago)
- Language: TypeScript
- Size: 41 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# z-index Manager
English | [简体中文](README.zh-CN.md)
[](https://gitee.com/x-extends/dom-zindex/stargazers)
[](https://www.npmjs.com/package/dom-zindex)
[](https://github.com/x-extends/dom-zindex/issues)
[](https://github.com/x-extends/dom-zindex/pulls)
[](https://unpkg.com/dom-zindex/dist/index.umd.min.js)
[](http://npm-stat.com/charts.html?package=dom-zindex)
[](LICENSE)
Web common z-index style management.
## Browser Support
 |  |  |  |  | 
--- | --- | --- | --- | --- | --- |
7+ ✔ | 80+ ✔ | 44+ ✔ | 40+ ✔ | 60+ ✔ | 6+ ✔ |
## Installing
```shell
npm install dom-zindex
```
## CDN
package gzip <= 900B
```HTML
```
## Example 1
```javascript
import domZIndex from 'dom-zindex'
// Gets the largest z-index on the page.
domZIndex.getMax()
// Set main current z-index.
domZIndex.setCurrent(1000)
// Get main current z-index.
domZIndex.getCurrent() // 1000
// Get main next z-index.
domZIndex.getNext() // 1001
// Get subordinate current z-index, the secondary z-index will always be greater than the primary z-index.
domZIndex.getSubCurrent() // 2001
// Get subordinate next z-index.
domZIndex.getSubNext() // 2002
```
## Example 2
```javascript
import domZIndex from 'dom-zindex'
// If the incoming z-index is less than global, the next one is automatically fetched.
let currZIndex1 = 888
currZIndex1 = domZIndex.getCurrent(currZIndex1) // 1000
// If the z-index is greater than the global value, the value is returned.
let currZIndex2 = 2000
currZIndex2 = domZIndex.getCurrent(currZIndex2) // 1500
```
## Css var
* Built-in following variables
* ```--dom-main-z-index``` 等于 ```getCurrent```()
* ```--dom-sub-z-index``` 等于 ```getSubCurrent```()
```css
.my-popup {
z-index: var(--dom-main-z-index);
}
.my-msg {
z-index: var(--dom-sub-z-index);
}
```
## Contributors
Thank you to everyone who contributed to this project.
[](https://github.com/x-extends/dom-zindex/graphs/contributors)
## License
[MIT](LICENSE) © 2019-present, Xu Liangzhan