Css Parrallax背景定位不正确
我试图在我们的演示网站上修复我们的视差效果,但就我而言,我无法让它正常工作。视差效果非常好,但是图像的定位在下面重复。当浏览器窗口不是全宽时会发生此问题Css Parrallax背景定位不正确,css,parallax,Css,Parallax,我试图在我们的演示网站上修复我们的视差效果,但就我而言,我无法让它正常工作。视差效果非常好,但是图像的定位在下面重复。当浏览器窗口不是全宽时会发生此问题 background: URL(http://www.oddpandadesign.co.uk/albaband/wp-content/uploads/2014/03/parallax_head.png) 50% 0 fixed; background-size: cover; jQuery jQuery(document).ready(
background: URL(http://www.oddpandadesign.co.uk/albaband/wp-content/uploads/2014/03/parallax_head.png) 50% 0 fixed;
background-size: cover;
jQuery
jQuery(document).ready(function(){
// cache the window object
$window = jQuery(window);
jQuery('section[data-type="background"]').each(function(){
// declare the variable to affect the defined data-type
var $scroll = jQuery(this);
jQuery(window).scroll(function() {
// HTML5 proves useful for helping with creating JS functions!
// also, negative value because we're scrolling upwards
var yPos = -($window.scrollTop() / $scroll.data('speed'));
// background position
var coords = '50% '+ yPos + 'px';
// move the background
$scroll.css({ backgroundPosition: coords });
}); // end window scroll
}); // end section function
}); // close out script
/* Create HTML5 element for IE */
document.createElement("section");
我不确定这是图像(虽然我们已经尝试了好几次)还是代码不正确。这不是第一次体验视差,它通常很简单,所以我有点困惑
谢谢你的帮助,我得换衣服了
background: URL(http://www.oddpandadesign.co.uk/albaband/wp-content/uploads/2014/03/parallax_head.png) 50% 0 fixed;
到
我在Chrome、Firefox和IE10中尝试了这个链接,在这三种浏览器上都很适合我。。。?没有奇怪的定位。编辑:现在我看到问题了。只有当您的浏览器窗口未100%最大化时才会发生此情况。。。您应该将其添加到描述中。:)@啊,你说得对。我将添加它。如果我将inspector中的
背景位置
值更改为50%0%
图像就可以了。您可以尝试更改jQuery,使坐标都是百分比?@speetje33您帮我修复了它!我必须使用背景位置:中上!重要的代码>在单独的行上。
background: URL(http://www.oddpandadesign.co.uk/albaband/wp-content/uploads/2014/03/parallax_head.png) fixed;
background-position: center top!important;