javascript - 响应图像背景质量问题

标签 javascript jquery html css image

我有一个标题,它会在用户通过 JavaScript 滚动经过某个点时改变大小。

当用户滚动超过 50px 时,类 .smaller 会添加到标题中,这会影响子元素,包括 Logo 。

但是,当调整 Logo DIV 元素的大小时,图像的质量似乎发生了变化;边缘看起来更加锯齿和锐利。

正常情况下是这样的:

enter image description here

并滚动:

enter image description here

这是 CSS:

div#header div.logo {
    width: 400px;
    height: 90px;
    margin: 5px;
    background: url(../img/logo.png) no-repeat center center;
    background-size:contain;
    float:left;
    padding:0 !important;
    -webkit-transition: all 0.3s;
       -moz-transition: all 0.3s;
        -ms-transition: all 0.3s;
         -o-transition: all 0.3s;
            transition: all 0.3s;
}

div#header.smaller div.logo {
    width:262px;
    height:40px;
    -webkit-transition: all 0.3s;
       -moz-transition: all 0.3s;
        -ms-transition: all 0.3s;
         -o-transition: all 0.3s;
            transition: all 0.3s;
}

相关的 JavaScript:

window.onload = init();

function init() {
    //header resize on scroll
    window.addEventListener('scroll', function(e){
        var distanceY = window.pageYOffset || document.documentElement.scrollTop,
            shrinkOn = 50,
            header = document.querySelector("#header");
        if (distanceY > shrinkOn) {
            classie.add(header,"smaller");
        } else {
            if (classie.has(header,"smaller")) {
                classie.remove(header,"smaller");
            }
        }
    });
}

为什么图像质量会发生如此明显的变化,如何避免这种情况?

最佳答案

当导航器动态调整图像大小时,图像变得模糊。 SVG 图像不会模糊您的 Logo 。
例如virtuehost.net/clients/go2markets 检查此站点并尝试调整此 Logo 的大小。

关于javascript - 响应图像背景质量问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31670577/

相关文章:

javascript - Node js 从模块化代码结构缩小并连接到单个文件

javascript - ReactJS 删除组件

javascript统计jquery数据表中选中的行数

javascript - JQuery动态改变html内容

Javascript print() 方法不起作用

javascript - 无法使用其选项动态创建选择

javascript - Mongoose 查询 "hot"帖子

javascript - 使用 setInterval() 创建计时器时出现问题 : updates way too quickly

javascript - 当页面添加1,滚动到底部

javascript - 如何防止 Bootstrap 下拉子菜单单击关闭父下拉菜单