我正在创建一个广告产品的布局,产品的功能位于占据浏览器全宽的 div 栏内。
我希望它在用户滚动时,屏幕中心的 div 将背景颜色从白色更改为浅灰色,以便专注于该功能。然后在用户继续下一个功能时返回白色。例子:
我使用 jquery scrollTop() 来找到滚动位置,然后根据您的滚动位置设置应突出显示的功能。问题是当浏览器调整大小时,功能 div 会改变高度,而我设置为最大宽度的滚动位置不起作用!下面是我用来生成转换的相关咖啡脚本。无论屏幕或浏览器大小如何,我怎样才能使这项工作?
$(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"