製品を宣伝するレイアウトを作成しています。製品の機能は、ブラウザの全幅を占める div バー内にあります。
ユーザーがスクロールすると、画面の中央にある div の背景色が白から明るい灰色に変わり、その 1 つの機能に集中できるようになります。その後、ユーザーが次の機能に進むと白に戻ります。例:
jquery scrollTop() を使用してスクロール位置を見つけ、スクロール位置に応じてどの機能を強調表示するかを設定します。問題は、ブラウザーのサイズが変更されたときに、機能 div の高さが変更され、最大幅に設定したスクロール位置が機能しないことです! 以下は、遷移を生成するために使用する関連する coffeescript です。画面やブラウザのサイズに関係なく、どうすればこれを機能させることができますか?
$(document).ready ->
scroll_pos = 0
$(document).scroll ->
scroll_pos = $(this).scrollTop()
scrollBottom = $(window).scrollTop() + $(window).height()
if scroll_pos < 300
$("#featureOne").css "background-color", "white"
$("#featureOne").css "-webkit-box-shadow", "none"
else if scroll_pos > 300 and scroll_pos < 730
$("#featureOne").css "background-color", "#eee"
$("#featureOne").css "-webkit-box-shadow", "0px 5px 15px 5px #eee"
$("#featureTwo").css "background-color", "white"
$("#featureTwo").css "-webkit-box-shadow", "none"
else if scroll_pos > 730 and scroll_pos < 1150
$("#featureOne").css "background-color", "white"
$("#featureOne").css "-webkit-box-shadow", "none"
$("#featureTwo").css "background-color", "#eee"
$("#featureTwo").css "-webkit-box-shadow", "0px 5px 15px 5px #eee"
$("#featureThree").css "background-color", "white"
$("#featureThree").css "-webkit-box-shadow", "none"
else if scroll_pos > 1150 and scroll_pos < 1700
$("#featureTwo").css "background-color", "white"
$("#featureTwo").css "-webkit-box-shadow", "none"
$("#featureThree").css "background-color", "#eee"
$("#featureThree").css "-webkit-box-shadow", "0px 5px 15px 5px #eee"
$("#featureFour").css "background-color", "white"
$("#featureFour").css "-webkit-box-shadow", "none"
else if scroll_pos > 1700 and scroll_pos < 2050
$("#featureThree").css "background-color", "white"
$("#featureThree").css "-webkit-box-shadow", "none"
$("#featureFour").css "background-color", "#eee"
$("#featureFour").css "-webkit-box-shadow", "0px 5px 15px 5px #eee"
$("#featureFive").css "background-color", "white"
$("#featureFive").css "-webkit-box-shadow", "none"
else if scroll_pos > 2050 and scroll_pos < 2450
$("#featureFour").css "background-color", "white"
$("#featureFour").css "-webkit-box-shadow", "none"
$("#featureFive").css "background-color", "#eee"
$("#featureFive").css "-webkit-box-shadow", "0px 5px 15px 5px #eee"
$("#featureSix").css "background-color", "white"
$("#featureSix").css "-webkit-box-shadow", "none"
else if scroll_pos > 2450 and scroll_pos < 2810
$("#featureFive").css "background-color", "white"
$("#featureFive").css "-webkit-box-shadow", "none"
$("#featureSix").css "background-color", "#eee"
$("#featureSix").css "-webkit-box-shadow", "0px 5px 15px 5px #eee"