Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

寻找(获取)当前页面中最大的 z-index 值的方法 #124

Open
GleanCoder1116 opened this issue Jan 20, 2021 · 0 comments
Open
Labels
高频面试 高频面试

Comments

@GleanCoder1116
Copy link
Member

常规方法:

const getMaxZIndex=() => {
 const zIndexArr = [...document.body.querySelectorAll('*')].map(e=>{
    return  Number(window.getComputedStyle(document.body).zIndex) || 0
 })
return Math.max(...zIndexArr)
}

在组件库中一般不用这个方法,组件库应该维护一个弹窗基础组件,在每一次的弹窗出现时候,均会对该次弹出的z-index进行记录,下次弹出就会在本次弹出的基础上+1

@GleanCoder1116 GleanCoder1116 added the 高频面试 高频面试 label Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
高频面试 高频面试
Projects
None yet
Development

No branches or pull requests

1 participant