0
我有很多列的表,我想基於瀏覽器寬度隱藏,所以我嘗試使用window.matchMedia(「(max-width:700)」)。matches,window .media(「(max-width:500)」)。matches等。在打字稿中,但我無法獲得媒體偵聽器。請找代碼How to you window.mediaQuery匹配typescript
for(let i : number =0 ; i< this.col.length; i++){
let media,
media = window.matchMedia(col[i].minWidth);
this.mcol.push(col[i])
this.mediaQueryUpdate(media)
media.addEventLister(mediaQueryUpdate)
}
public medaiQueryUpdate(e:any){
if(window.matchMedia(e.target.media).match){ // did not get target e , error thrown as e does not found
for(let c: number =0 ; c< this.mcol.length; c++){
if(window.matchMedia(e.target.media) == this.mcol[c].minWidth){
// did nto get target from e
mcol[c].hide= true;
}
}
}
你爲什麼不使用CSS來做到這一點的原因嗎? – toskv
我們不知道它動態獲取最大寬度/最小寬度 –
你仍然可以在CSS中將display屬性設置爲none。 – toskv