私の質問は、.offset() を使用してブラウザーの y 位置を見つけることです。ある時点で、div にクラスを追加したいのですが、yourkarma.comのようなものを作成したいと考えています(「IT の動力源」セクションを参照してください)。
$(document).ready(function() {
$(window).scroll(function (event) {
// what the y position of the scroll is
var z = '150';
var x = $('#thisdiv').offset().top - z;
var y = $(this).scrollTop();
// whether that's below the form
if (y >= x) {
// if so, ad the fixed class
$('#thisdiv').addClass('red');
}
});
})
私は正しい道を進んでいますか?私は z=150 を使用し、それを X に差し引くのはちょっと安上がりな方法だと思います。もっと良いものを作る方法はありますか?