サイドメニューの一部がスクロールに応じて付いて来る設定をjavascriptでしました。
設定したのはいいのですが、実装した要素のwidthが効かなくなり、広がり、また記事などがなくスクロールできない長さのページの場合、認識されずfooterを踏みつけ&footerの下にまで要素が繋がっています。(それなりの長さをもつ要素なので)
javascriptに使っているのはid="float-box"です。このid(とjavascriptのコード)がなければ、今まで通りのwidrhを保ち、footerも要素の下に配置されます。
main.php
php
1<!--------------------略-----------------------> 2 <section class="col-sm-12 order-sm-3 sp-lg-4 order-lg-3" id="rightSidebarSection"> 3 <?php get_template_part("./template/mainSidebar"); ?> 4 </section> 5<!--------------------略----------------------->
mainSidebar.php
php
1<div id="float-box"> 2<h2 class="mainSiderbarTitle">スクロールする要素</h2> 3 4 <?php 5 $args = array( 6 'posts_per_page' => 5, 7 'meta_query' => array( 8<!--------------------略-----------------------> 9 <?php endif; 10 wp_reset_postdata(); 11 ?> 12</div> 13 14<script type="text/javascript"> 15 var setBoxId = '#float-box'; 16 var scrollStart = null; 17 var scrollEnd = null; 18 var floatBoxTop = 10; 19 $(document).ready(function() { 20 scrollStart = $(setBoxId).offset().top; 21 scrollEnd = $(document).height() - 1000 22 }) 23 $(window).scroll(scroll) 24 25 function scroll(){ 26 var scrollTop = $(document).scrollTop() + floatBoxTop; 27 scrollTop = Math.min(scrollEnd, Math.max(scrollTop, scrollStart)) 28 if(scrollTop === scrollStart || scrollEnd === scrollTop) { 29 $(setBoxId).css({ 30 position:'absolute', 31 top: scrollTop 32 }); 33 } else { 34 $(setBoxId).css({ 35 position: 'fixed', 36 top: floatBoxTop 37 }); 38 } 39 } 40</script>
css
1#float-box{ 2 position: absolute; 3} 4#rightSidebarSection { 5 border-left: 1px solid #efefef; 6}
main.phpの<section class="col-sm-12 order-sm-3 sp-lg-4 order-lg-3" id="rightSidebarSection">のクラスとidを反映させたいです。
class="col-sm-12 order-sm-3 sp-lg-4 order-lg-3"に関しては、添付した写真の通りです。
このファイルがどういうものなのか、なぜ詰まっており、途中からいろが薄いのかなど理解しておりません。
どうしたら、反映させられるか、またどう調べたらいいか教えていただけたらと思います。
よろしくお願いします。