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

supportWebp() will append a '!' #150

Closed
BoltDoggy opened this issue May 19, 2017 · 7 comments
Closed

supportWebp() will append a '!' #150

BoltDoggy opened this issue May 19, 2017 · 7 comments
Labels

Comments

@BoltDoggy
Copy link

BoltDoggy commented May 19, 2017

function supportWebp () {
    if (!inBrowser) return false

    let support = true
    const d = document

    try {
        let el = d.createElement('object')
        el.type = 'image/webp'
        el.innerHTML = '!'
        d.body.appendChild(el)
        support = !el.offsetWidth
        d.body.removeChild(el)
    } catch (err) {
        support = false
    }

    return support
}

在没有使用 vue-ssr 的情况下,页面由 vue 进行前端渲染,会导致一开始白屏的时候,出现一个 ‘!’ 一闪而过

@LingF
Copy link

LingF commented May 24, 2017

也遇到了这个情况!

@hilongjw
Copy link
Owner

这样应该可以解决这个问题,稍后修复这里

function supportWebp () {
    if (!inBrowser) return false

    let support = true
    const d = document

    try {
        let el = d.createElement('object')
        el.style.display = 'none'
        el.type = 'image/webp'
        el.innerHTML = '!'
        d.body.appendChild(el)
        support = !el.offsetWidth
        d.body.removeChild(el)
    } catch (err) {
        support = false
    }

    return support
}

@BoltDoggy
Copy link
Author

display: none 会使 offsetWidth 值 为 0, support 的值就不准确了,可以使用 visibility: hidden;

@hilongjw hilongjw added the bug label May 26, 2017
@hilongjw
Copy link
Owner

@lc60005457 感谢,稍后会在新版本修复这里

@LingF
Copy link

LingF commented Aug 9, 2017

现在暂时样式里面匹配了这个元素
object[type="image/webp"] { visibility: hidden; }

@hilongjw
Copy link
Owner

@LingF 在新版中增加了对这个webp支持检测元素的隐藏,可以不用通过增加css 解决了。https://github.com/hilongjw/vue-lazyload/blob/master/src/util.js#L111

@LingF
Copy link

LingF commented Aug 16, 2017

@hilongjw nice

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

3 participants