特定のポイントまでスクロールしたときに、ページの要素をページと共にスクロールダウンさせようとしています。position: fixed
動く別の要素が当たったときに切り替えます。問題は、切り替えたときにposition: fixed
、ページの約 4 分の 1 下に移動することです。これは、ページ上の元の位置であるためです。元の位置にジャンプする代わりに、固定に切り替わった位置を使用する方法はありますか?
ここにいくつかのコードがあります:
jQuery(window).scroll(function (event) {
var top = jQuery("accordion").offset().top - parseFloat(jQuery("#accordion").css("marginTop").replace(/auto/, 0));
// what the y position of the scroll is
var y = jQuery( "#navigation" ).offset().top + jQuery( "#navigation" ).height();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
jQuery("#accordion").css('position','fixed');
} else {
// otherwise remove it
jQuery("#options_accordion").css('position', '');
}
});