position: fixed;
のdivを持っている場合は、スクロールダウン時に特定の時刻にposition: absolute;
がある。 私の問題は、私のdivのposition: fixed;
が私のフッターの上部に依存していることです。しかし、私のフッタの上端は変更されますが、私のdivが '修正'されるべき部分の制限はありません。たぶん、コードがより明確になります:関数をリロードする方法(イベント)
HTML:
<div id="header" style="height:500px; width:800px; border: 5px solid green; " >
header
</div>
<div id="top" style="height:3000px; width:800px; border: 5px solid yellow; " >
<button onclick="ReduceSize()"> Reduce size </button>
<div id="comment" style="padding-bottom:30px; height:700px; width : 300px; margin-left:30px; border: 5px solid orange;" >
</div>
</div>
<div id="bottom" style="height:3000px; width:800px; border: 5px solid green; " >
footer
</div>
JS:事前に
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'>
</script>
<script>
function ReduceSize() {
var obj = document.getElementById('top');
obj.style.height = "750px";
}
$(document).ready(function() {
var haut = $('#comment').offset().top;
var hautBottom = $('#bottom').offset().top - parseFloat($('#comment').css('height').replace(/auto/, 0) ) ;
$(window).scroll(function (event) {
var y = $(this).scrollTop();
if( (y >= (haut-20)) && (y < hautBottom) ) {
$('#comment').css({ position: 'fixed', top:20 });
}else{
if(y >= haut){
$('#comment').css({ position: 'absolute', top:hautBottom });
}
if(y < hautBottom){
$('#comment').css({ position: 'absolute', top:parseFloat( $('#top').offset().top) });
};
};
});
});
</script>
感謝。
フッターの上部にオーバーレイする#commentを防止したいですか? – Syden