positoin: sticky;
を使用して、下記の動きを実装しました。
url(https://codepen.io/yutas01/pen/jOEWdzm
しかしpositoin: sticky;
はIE11に対応していません。
これをIE11に対応させたく、Stickyfillや、Fixed Stickyなどのプラグインを試したのですが、なぜか小さいディスプレイで見ると上手く表示されるのですが、ディスプレイが大きくなると崩れるという現象が起きてしまいました。
原因が分からず、結局display: relative;
とdisplay: fixed;
をjsで制御して表示させるやり方を試みたのですが上手くいかず、この場合どのように記述すればよいのでしょうか。
私自身、色々と調べてみたのですが、display: relative;
とdisplay: fixed;
を使用する方法でも途中で固定し続ける方法しか見つからず、固定しない
→固定する
→固定しない
の動きが付けられませんでした。
ご回答いただけますと幸いです。
html
1<div class="container"> 2 <div class="cont1"> 3 <div class="drop-img drop-img2"> 4 <img src="https://dl.dropbox.com/s/rkox4afc0kmkfj1/drop.png?dl=0" alt=""> 5 <p class="drop-year"> 6 2019 7 </p> 8 </div> 9 </div> 10 <div class="cont2"> 11 <div class="drop-img drop-img3"> 12 <img src="https://dl.dropbox.com/s/rkox4afc0kmkfj1/drop.png?dl=0" alt=""> 13 <p class="drop-year"> 14 2018 15 </p> 16 </div> 17 </div> 18 <div class="cont3"> 19 <div class="drop-img"> 20 <img src="https://dl.dropbox.com/s/rkox4afc0kmkfj1/drop.png?dl=0" alt=""> 21 <p class="drop-year"> 22 2017 23 </p> 24 </div> 25 </div> 26 <div class="cont4"> 27 <div class="drop-img"> 28 <img src="https://dl.dropbox.com/s/rkox4afc0kmkfj1/drop.png?dl=0" alt=""> 29 <p class="drop-year"> 30 2016 31 </p> 32 </div> 33 </div> 34</div>
css
1.container { 2 position: relative; 3 4 &::before { 5 content: ''; 6 position: absolute; 7 left: 0; 8 right: 0; 9 background: #00a0e9; 10 width: 3px; 11 height: 100%; 12 margin: auto; 13 } 14} 15 16.drop { 17 &-img { 18 position: sticky; 19 top: 45%; 20 text-align: center; 21 right: 0; 22 left: 0; 23 24 img { 25 width: 80px; 26 } 27 } 28 29 &-year { 30 position: absolute; 31 color: #fff; 32 left: 0; 33 right: 0; 34 top: 20px; 35 } 36} 37 38.cont1 { 39 background: #FFDEFF; 40 height: 600px; 41 text-align: center; 42} 43 44.cont2 { 45 background: #DEFFFF; 46 height: 600px; 47 text-align: center; 48} 49 50.cont3 { 51 background: #FFFFDE; 52 height: 600px; 53 text-align: center; 54} 55 56.cont4 { 57 background: #C7FFC7; 58 height: 600px; 59 text-align: center; 60} 61
js
1$(window).scroll(function() { 2 var wH = $(window).height(); 3 $('.drop-img').each(function(){ 4 var dropH = $(this).offset().top; 5 if ( dropH < $(window).scrollTop() + (wH/2.5)) { 6 $(this).children('img').attr('src', 'https://dl.dropbox.com/s/ns0be5m1vp0611t/drop_gray.png?dl=0'); 7 } else { 8 $(this).children('img').attr('src', 'https://dl.dropbox.com/s/rkox4afc0kmkfj1/drop.png?dl=0'); 9 } 10 }); 11})
あなたの回答
tips
プレビュー