表題の通り、edgeで固定背景のバグがあるので、回避する方法があれば、教えてほしいです。
html
1<div class="st-skew" id="sc-skew"> 2 <ul> 3 <li> 4 <section> 5 <h3>title</h3> 6 <p>text</p> 7 </section> 8 </li> 9 <li> 10 <section> 11 <h3>title</h3> 12 <p>text</p> 13 </section> 14 </li> 15 <li> 16 <section> 17 <h3>title</h3> 18 <p>text</p> 19 </section> 20 </li> 21 </ul> 22</div>
SCSS
1.st-skew{ 2 transform: skewX(8.6deg) rotate(8.6deg); 3 width: 100%; 4 background-color: hsl(212, 100%, 27%); 5 box-shadow: 0 4px 2px hsla(0, 0%, 0%, 0.2); 6 ul{ 7 margin: 40px auto 70px; 8 padding: 40px 0; 9 display: flex; 10 justify-content: center; 11 position: relative; 12 z-index: 1; 13 background-image: url(../images/image01.jpg); 14 background-repeat: no-repeat; 15 background-size: cover; 16 background-attachment: fixed; 17 } 18 li{ 19 width: 250px; 20 transform: rotate(-8.6deg) skewX(-8.6deg); 21 p{ 22 line-height: 1.75; 23 color: #fff; 24 } 25 } 26 li:nth-child(2){ 27 margin: 0 40px; 28 } 29}
こちらの記述でedge以外は動くのですが、
出来ればedgeでも動くようにしたい。
before要素などそこにバックグラウンドを指定して
position:fixed;なども試したが、だめでした。
追記
仕様:斜めに傾けたコンテンツに固定の背景を設定している。
edge以外のブラウザでは、背景は固定されているが、
edgeだと背景は固定ではなくなる。
原因はbackground-attachment: fixedとtransformの混在によるもの
firefoxでもedgeと同様になる
解決案
JavaScript
1const fixedScroll = document.querySelector('#sc-skew ul') 2window.onscroll = e => { 3 fixedScroll.style.backgroundPositionY = `${window.pageYOffset}px`; 4}
IE11に対応するなら(アロー関数とテンプレートリテラルが使えないため)
JavaScript
1window.addEventListener('scroll', function(){ 2 fixedScroll.style.backgroundPositionY = window.pageYOffset + "px"; 3})
ご協力ありがとうございました。
回答2件
あなたの回答
tips
プレビュー