小编Dom*_*ran的帖子

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

我在我的网站上实现了以下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"});
});
Run Code Online (Sandbox Code Playgroud)

它工作得很好,我需要做的就是将它应用到包含背景的类中.但是,背景图像的起始位置是顶部中心,我想将其更改为居中中心.我已经尝试将代码更改为以下内容,这使插件停止工作:

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

有什么建议?

谢谢!

jquery background parallax

1
推荐指数
1
解决办法
7052
查看次数

标签 统计

background ×1

jquery ×1

parallax ×1