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

css函数之-webkit-image-set #10

Open
chenxiaochun opened this issue May 22, 2017 · 0 comments
Open

css函数之-webkit-image-set #10

chenxiaochun opened this issue May 22, 2017 · 0 comments
Labels

Comments

@chenxiaochun
Copy link
Owner

chenxiaochun commented May 22, 2017

一种非常简单的,根据用户分辨率显示匹配的背景图片语法,直接看示例代码:

<div class="chat"></div>
.chat{
    width: 64px;
    height: 64px;
    background-image: 
        -webkit-image-set(
            url(http://img10.360buyimg.com/uba/jfs/t5707/365/1158255807/1895/329457d4/59240e76N267f7463.png) 1x,
            url(http://img13.360buyimg.com/uba/jfs/t5611/202/1160227732/3765/ae72281a/59240dacN3f1a8d77.png) 2x
    );
    background-repeat: no-repat;
    background-size: 100% 100%;
}

各位应该注意到,我用了一个全新的css函数:-webkit-image-set,它后面写了两组背景图片url和相应的设备相素比。只需要如此简单的语法,浏览器就会知道在相应的设备像素比中下载显示不同的背景图片了。

为了照顾浏览器兼容性,我们就只能用下面这种渐近增强的写法,在不支持的浏览器上它会自动忽略-webkit-image-set

.chat{
    width: 64px;
    height: 64px;
    background-image: url(http://img10.360buyimg.com/uba/jfs/t5707/365/1158255807/1895/329457d4/59240e76N267f7463.png);
    background-image: 
        -webkit-image-set(
            url(http://img10.360buyimg.com/uba/jfs/t5707/365/1158255807/1895/329457d4/59240e76N267f7463.png) 1x,
            url(http://img13.360buyimg.com/uba/jfs/t5611/202/1160227732/3765/ae72281a/59240dacN3f1a8d77.png) 2x
        );
    background-repeat: no-repat;
    background-size: 100% 100%;
}

image

@chenxiaochun chenxiaochun changed the title -webkit-image-set css函数之-webkit-image-set May 25, 2017
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

1 participant