jQuery - 视差效果 - 将背景位置更改为 "Center Center"

jQuery - Parallax Effect - Change Background Position to "Center Center"

我已经在我的网站中实现了以下 jQuery 视差效果(摘自 http://www.brandaiddesignco.com/insights/parallax-scrolling-made-easy/):

var top_header = '';
$(document).ready(function(){
  top_header = $('.header-container');
});
$(window).scroll(function () {
  var st = $(window).scrollTop();
  top_header.css({'background-position':"center "+(st*.5)+"px"});
});

效果很好,我需要做的只是将它应用到包含背景的 class。但是,背景图片的起始位置是top center,我想把它改成center center。我尝试将代码更改为以下内容,这使插件停止工作:

top_header.css({'background-position':"center center"+(st*.5)+"px"});

有什么建议吗?

谢谢!

想通了...让它与 CSS calc() 一起工作:

$(document).ready(function(){

var top_header = $('.header-container');
top_header.css({'background-position':'center center'}); // better use CSS

$(window).scroll(function () {
var st = $(this).scrollTop();
top_header.css({'background-position':'center calc(50% + '+(st*.5)+'px)'});
});
});

http://codepen.io/anon/pen/qEgQzK?editors=001

原始答案已编辑。