【问题标题】:Blurry image after scale in Safari and Chrome在 Safari 和 Chrome 中缩放后图像模糊
【发布时间】:2016-09-27 22:00:33
【问题描述】:

我有一个大图像作为背景图像,我在滚动时减小了尺寸,同时我也修改了背景位置。

不幸的是,我在 Chrome 和 Safari 中发现了问题。在这些浏览器中,一旦我开始滚动图像就会变得模糊。

我为这个问题尝试了很多解决方案,但没有运气。您是否知道出了什么问题,或者有什么其他方法可以帮助达到同样的效果?

JS

function promo_scroll() {
    var current_scroll = jQuery(window).scrollTop();
    var scale = 5;
    var window_height = jQuery(window).height();
    var window_width = jQuery(window).width();
    var correction = jQuery('#header-wrapper').height()-500;

    if(scale*((1-(current_scroll/window_height))) > 1 && (window_width/window_height >= 198/119)) {
        jQuery('#custom-header').removeAttr('data-top');

        jQuery('.container').css({
            'position'  : 'fixed',  
            'display' : 'block',
            'top': 0,
            'left': 0,
            'transform' : 'scale(' + scale*((1-(current_scroll/window_height))) + ')',
        });

        jQuery('.container:not(.content)').css('background-position', '0 ' + correction + 'px');


    } else if(window_width/window_height >= 198/119) {
        if (typeof jQuery('#custom-header').attr('data-top') == 'undefined'){
            jQuery('#custom-header').attr('data-top',jQuery('#custom-header').offset().top);
            jQuery('#content-wrapper').css('padding-top',jQuery('#custom-header').offset().top);
        }
        jQuery('.container').css({
            top : jQuery('#custom-header').attr('data-top')-current_scroll,
            'transform' : 'scale(1)',
        });
    }
    else{
        jQuery('#custom-header').removeAttr('data-top');
        jQuery('#content-wrapper').css('padding-top',0);

        jQuery('.container').css({
            'background-position': 'center top',
            'position'  : 'absolute',   
            'top': 0,
            'left': 0,
            'transform' : 'scale(1)',
        });
        jQuery('.container.content').css({
            'position' : 'absolute'
        });
    }
}

jQuery(document).on('click','#custom-header', function(){
    jQuery('html, body').animate({'scrollTop': jQuery('.l-grid-row').offset().top - jQuery('#main-header').outerHeight()},2500);
});

jQuery(document).ready(function(){
    promo_scroll();
});

jQuery(window).on('scroll', function(){
    jQuery('.container.content')[0].style.setProperty('background-position', jQuery(window).scrollTop() + 'px 50%', 'important');
    promo_scroll();
});

jQuery(window).on('resize', function(){
    jQuery('#custom-header').removeAttr('data-top');
    promo_scroll();
});

CSS

body {
    -webkit-font-smoothing: antialiased;
}

.container {
    height: 100%; 
    width: 100%;
    z-index: 6;
    will-change: transform;
filter: none; 
-webkit-filter: blur(0px); 
-moz-filter: blur(0px); 
-ms-filter: blur(0px);
filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='0');
}

.container.content{
    z-index: 5;
    background-image:url('http://i.imgur.com/f68DPZG.jpg');
    background-position: left center;
    background-repeat: repeat-x;
}

#header-wrapper {
    display: none;
}

@media screen and (min-width: 767px) {
    #header-wrapper {
        display: block;
    }
}

@media screen and (min-aspect-ratio: 198/119) {
    .container {
        -webkit-transform: scale(5);
        -moz-transform: scale(5);
        transform: scale(5);
        background-size: 100% auto !important;
        background-position: center center !important;
    }
}

.spacing {
    height: 2000px;
}

HTML

<div id="header-wrapper" data-full-height-header="true">
    <div id="custom-header" class="container"></div>
    <div class="container content"></div>
</div>
<div class="spacing">
</div>

效果仅在特定纵横比下可见,因此请全屏查看链接:https://jsfiddle.net/4eod1ng5/3/embedded/#Result

更新:经过多次测试,问题似乎只出现在 OSX(Safari 和 Chrome)中 更新 2: 在我将我的 chrome 在 linux 中更新为 51 后,问题出现了。

【问题讨论】:

  • 存在一些缩放问题。

标签: css css-transitions transform css-animations css-transforms


【解决方案1】:

不幸的是,您的小提琴对我来说效果不佳,我可以看到某种奇怪之处,但是当我编辑它时我无法运行小提琴。但是,在我的脑海中运行代码:

您将比例与模糊效果结合使用。当您使用比例 5 时,它不会重新初始化效果,而只会放大对象。我会尝试从大尺寸(宽度 + 高度 = 500%)开始,而不是缩小(比例

您也可以尝试使用背景图像转换容器而不是对象。这在处理此类问题时偶尔对我有所帮助。

【讨论】:

  • 是的,您可以全屏运行小提琴,因为它适用于特定的纵横比。我会试试那个方法,谢谢。
  • 你有时间尝试一下吗?
【解决方案2】:

我尝试了 jsFidle。我在这里看到的问题是因为图像分辨率低,请尝试使用更高分辨率的图像

【讨论】:

  • 如果图像分辨率较低,您在初始加载时也会看到模糊的图像,而不仅仅是滚动后。图片尺寸为:6144px × 822px。如果您在 chrome 中尝试过,您可以看到初始加载和滚动后之间的差异。
  • 822px 很低,它的宽度确实是 6144px,但图像高度很低我在 4k 屏幕上的 windows 上的 chrome 上对其进行了测试,我看到问题一直向上滚动。我可以告诉你,如果你使用高度超过 2000 像素的图像,你不会看到问题
  • 请检查所附图片。当然,第一张不如高清照片锐利,但比第二张锐利。它出现在 osx chrome 和 safari 中,所以如果你有 Linux/Windows,你不会看到它。
  • 在 linux 中将我的 chrome 更新为 51 后,问题出现了。所以这不是 osx 特定的错误。
  • 你可以试试这个 iamge onedrive.live.com/…
猜你喜欢
  • 1970-01-01
  • 2015-04-27
  • 2016-10-20
  • 2020-01-17
  • 2012-12-19
  • 1970-01-01
  • 2020-12-09
  • 2014-06-07
  • 1970-01-01
相关资源
最近更新 更多