I am creating a layout advertising a product, and the features of the product are inside a div bar that takes up the full width of the browser.
I want it so as the user scrolls, the div in the center of the screen changes the background color from white to light gray, as to focus in on that one feature. Then return back to white as the user continues to the next feature. Example:
I achieve this using jquery scrollTop() to find the scroll position, then set which feature should be highlighted depending on your scroll position. The issue is when the browser is resized, the feature divs change height and the scroll position I set at max width do not work! Below is the relevant coffeescript I use to generate the transitions. How can I make this work no matter what screen or browser size?
$(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"