課程
/前端開發(fā)
/HTML/CSS
/CSS深入理解之z-index
聽了老師的課,百度找了下js如何獲取body下子元素的最大z-idnex值,找不到,哪位大神知道的,求分享,十分感謝。
2016-12-05
源自:CSS深入理解之z-index 8-1
正在回答
技術(shù)有限,我的方法比較死板。代碼如下:
var?DOMs?=?document.all;//獲取所有DOM var?maxIndex?=?0;//最大z-index var?curIndex?=?0;//當(dāng)前z-index for(var?i?=?0;i?<?DOMs.length;i++){ ????curIndex?=?document.defaultView.getComputedStyle(DOMs[i],null)["z-index"];//獲取z-index的值 ????curIndex?=?curIndex?==?"auto"???0?:?1; ????maxIndex?=?curIndex?>?maxIndex???curIndex?:?maxIndex; } console.log(maxIndex);
雨中的魚L 提問者
月下風(fēng)物語 回復(fù) 雨中的魚L 提問者
雨中的魚L 提問者 回復(fù) 月下風(fēng)物語
let arr = [...document.all].map(ele => +window.getComputedStyle(ele).zIndex || 0);
let maxZ = arr.length ? Math.max(...arr) : 0;
console.log(maxZ);
舉報(bào)
CSS技術(shù)大牛深入理解系列又一力作,z-index實(shí)踐經(jīng)驗(yàn)分享
3 回答該如何理解父元素設(shè)置position后不會覆蓋img,而img的兄弟元素設(shè)置position后會覆蓋img?如何從z-index層面理解?
1 回答老師,根元素的z-index是等于0吧?
3 回答產(chǎn)生層疊上下文的元素是不是同時(shí)z-index=auto呢?
3 回答視頻中inline-block與block元素的層疊順序如何理解
2 回答定位元素默認(rèn)z-index: auto,可以看成z-index: 0,這條規(guī)則,img標(biāo)簽可以,為什么span不可以,同樣都是inline呀
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-12-12
技術(shù)有限,我的方法比較死板。代碼如下:
2019-12-07
let arr = [...document.all].map(ele => +window.getComputedStyle(ele).zIndex || 0);
let maxZ = arr.length ? Math.max(...arr) : 0;
console.log(maxZ);