-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
移动端访问时,iframe 首次的高度可能会很大(1900左右),但是 resize 后恢复正常(比如切换横竖屏)。
caniuse-embed/src/scripts/feature.ts
Lines 40 to 58 in 9d18b36
function hashchange() { | |
const hash | |
= window.location.hash.slice(1) || window.location.search.slice(1) | |
const search = new URLSearchParams(hash) | |
meta = noNullable(search.get('meta'), '') | |
const past = toNum(noNullable(search.get('past'), '2')) | |
const future = toNum(noNullable(search.get('future'), '1')) | |
const list: string[] = [] | |
Array.from({ length: past }).fill(0).forEach((_, i) => list.push(`past_${i + 1}`)) | |
Array.from({ length: future }).fill(0).forEach((_, i) => list.push(`future_${i + 1}`)) | |
el?.setAttribute('class', `feature ${list.join(' ')}`) | |
themeMode = noNullable(search.get('theme'), 'auto') | |
if (themeMode !== 'auto') | |
updateTheme(themeMode === 'dark') | |
resize() | |
} |
看了一下 feature.ts 里,首次传递高度是 hashchange 触发的 resize 然后传递高度,这个时候 .feature
主体是否可能存在未加载完成,最终导致第一次高度获取异常呢?
我在使用 官网 的 p 标签嵌入,亦或是我正在开发尝试使用的 caniuse-embed-element 方式都存在首次高度加载异常的问题。希望大佬帮忙解决一下。
在 DOMContentLoaded
里直接执行也还是高度值不对,我尝试延迟执行 hashchange
方法是有效的,但是这肯定不是一个好的方式😂
initTheme()
setEmbedLink()
document.addEventListener('DOMContentLoaded', () => {
on('hashchange', hashchange)
on('resize', resize)
setTimeout(() => {
hashchange()
}, 3000)
})
Metadata
Metadata
Assignees
Labels
No labels