jQuery(function ($) {
$(window).scroll(function() {
var y = $(this).scrollTop();
if (y > 360) {
var pos_yvalue = y - 294;
$('.site-header .wrap').css('background-position-y',
pos_yvalue.toString() + 'px');
}
});
});
通过以上我想在卷绕头(.site-header .wrap
)中的图像设置为背景位置Y元素一个背景位置-Y相对于涡旋的y位置。组相对基于滚动
因此,当我滚动以上为360px然后我想要放置站点头.wrap的背景图像是66,并且当它是362中的包裹物的背景图像应该是65等
以上代码将代表值66,67,68等,而不是像这样向下计数:66,65,64,63,62,61等。
由于某种原因,我无法理解这一点。
您是否尝试过使用'VAR screenTop = $(文件).scrollTop(); $('#content').css('top',screenTop);'看到第二个答案在这里 - http://stackoverflow.com/questions/7019353/jquery-how-to-get-the-pages-current-屏幕上方的位置。你也使用这个移动设备?可能需要为移动事件添加库。另请参阅滚动值的这篇文章(您需要将jquery> 1.9的'bind'更改为'on - https://stanhub.com/how-to-get-element-distance-from-top-jquery -offset/ –
当然,手机已经被考虑到了,但暂时还没有。 – bestprogrammerintheworld