【问题标题】:Firefox transform and background attachment fixed not workingFirefox 转换和背景附件固定不工作
【发布时间】:2017-02-07 15:19:14
【问题描述】:

我正在处理带有倾斜部分的全宽视差类型页面。问题在于 Firefox 中的 transform:skew() 似乎弄乱了 background-attachment:fixed 属性。它适用于 Chrome、Safari 和 IE11,但不适用于 Firefox。

有没有人知道这个问题的任何变通方法或修复?

example of my code

$(function() {
    function resizingScript() {
        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        var clipSize = 114;

        $('.section-wrap.top').outerHeight( windowHeight+clipSize );
        $('.section-wrap.middle').outerHeight( windowHeight+clipSize*2 );
        $('.section-wrap').css('margin-top', -(clipSize/2));
        $('.section-wrap .section-intro, .section-wrap .section-design').css('padding-bottom', clipSize/2);
        
        var $el = $('.section-wrap');
        $el.each(function (i) {
            $(this).css('z-index', ($el.length - i)+20);
        });
        
    }
    
    resizingScript();
});
#section-container {
    height: 100%;
}

.max-width-container {
    position: relative;
    max-width: 1920px;
    margin: 0 auto;
}

.section-wrap {
    position: relative;
    height: 100%;
    -webkit-transform: skew(0,-5deg);
    -moz-transform: skew(0,-5deg);
    -o-transform: skew(0,-5deg);
    -ms-transform: skew(0,-5deg);
    transform: skew(0,-5deg);
    overflow: hidden;
}

.section-wrap .section-intro,
.section-wrap .section-design {
    -webkit-transform: skew(0,5deg);
    -moz-transform: skew(0,5deg);
    -o-transform: skew(0,5deg);
    -ms-transform: skew(0,5deg);
    transform: skew(0,5deg);
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
}

.content-section {
    width: 100%;
    background-size: 100% auto;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    overflow: hidden;
    padding-top: 100px; 
}

#section-intro .intro-a {
    background-color:red;
}

#section-design .intro-a {
    background-color:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div id="section-container" class="max-width-container">
        <div class="section-wrap top">
            <div id="section-intro" class="section-intro">
                <div class="intro-a content-section">

                </div>
            </div>
        </div>
        
        <div class="section-wrap middle">
            <div id="section-design" class="section-design">
                <div class="intro-a content-section">

                </div>
            </div>
        </div>
</div>

【问题讨论】:

    标签: html css firefox css-transforms background-attachment


    【解决方案1】:

    对此的简单修复没有多大运气,但找到了一个 jQuery 解决方法here

    if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
            $('.content-section').css('background-attachment', 'scroll');
            $('.section-wrap.middle .content-section').css('background-size', '107%');
            $(window).scroll(function(){
                scrollTop = $(window).scrollTop();
                $('.content-section').each(function(i, el){
                    photoTop = $(this).offset().top + clipSize/2;
                    console.log(photoTop);
                    distance = (photoTop - scrollTop);
                    $(this).css('background-position-y', (distance*-1) + 'px');
                });
            });
        }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2016-09-04
      • 2015-04-16
      • 1970-01-01
      • 2012-04-04
      • 2018-05-17
      • 2017-01-30
      相关资源
      最近更新 更多