0
点赞
收藏
分享

微信扫一扫

使用querySelectAll给元素设置样式

兔八哥软件爱分享 2022-01-11 阅读 77

该笔记应用场景: 全局定义的header 和footer 样式浮在弹窗的黑色阴影上,使用querySelectAll改变元素的display/zIndex
MDN 链接:
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelectorAll

showRecommend(val){
			let headerDom = document.querySelectorAll('.fix-header'),
				footerDom = document.querySelectorAll('.fix-footer');
			debugger;
			if (val) {
				if (footerDom && footerDom.length) {
					for (const n of headerDom) {
						n.style.zIndex = 0
					}
					for (const n of footerDom) {
						n.style.display = 'none'
					}
				}
			}else{
				if (footerDom && footerDom.length) {
					for (const n of headerDom) {
						n.style.zIndex = 9
					}
					for (const n of footerDom) {
						n.style.display = 'flex'
					}
				}
			}
		}
举报

相关推荐

0 条评论