简体   繁体   English

StellarJs 视差背景图像不起作用

[英]StellarJs parallax background image not working

I know there are other similar questions on this, believe me, I have been at this for almost two days now.我知道还有其他类似的问题,相信我,我已经讨论了将近两天了。

I am trying to use StellarJs to create a parallax background image in the header of my website.我正在尝试使用 StellarJs 在我网站的标题中创建一个视差背景图像。 Unfortunately, it is having no effect whatsoever on the element with the specified data-stellar-background-ratio .不幸的是,它对具有指定data-stellar-background-ratio的元素没有任何影响。

Here is a demo (with a different bg image than on my local machine).这是一个演示(与我的本地机器上的 bg 图像不同)。

I even made a version exactly like the example on the website and it still would not work.我什至制作了一个与网站上的示例完全相同的版本,但它仍然无法正常工作。 I looked into solutions on 4 other similar questions, none of which helped me.我研究了其他 4 个类似问题的解决方案,但没有一个对我有帮助。 I'm at a loss here.我在这里不知所措。

Okay, so I can't speak to your local copy but I know that at least this one I fixed by moving the Stellar source code to an external resource and then adding a missing );好的,所以我无法与您的本地副本交谈,但我知道至少通过将 Stellar 源代码移动到外部资源然后添加缺失的);修复这个副本); at the end of the $(document).ready() function and fixing that syntax error.$(document).ready()函数的末尾并修复该语法错误。 You may want to check your local version to see if you have something similar, and check your dev tools' console to see if there are any syntax issues you're missing.您可能需要检查您的本地版本以查看是否有类似的内容,并检查您的开发工具的控制台以查看是否存在您遗漏的任何语法问题。

After punching a few holes in the drywall I realized that the problem had nothing to do with the element in question or the way I was calling the stellar function.在石膏板上打了几个洞后,我意识到问题与所讨论的元素或我调用恒星函数的方式无关。 It had to do with this little piece of CSS right here:它与这里的一小段 CSS 有关:

html, body {
    overflow-x: hidden;
    height: 100%;
}

It seems you cannot apply a height of 100% to the html and body tags, because after removing that height declaration, it works like a charm!似乎您不能将 100% 的高度应用于htmlbody标签,因为在删除高度声明后,它就像一个魅力! I'm so confused as to why, and I will be contacting the creator of StellarJs to see if it is a bug or if it is intentional/expected behavior for some reason that I am overlooking.我很困惑为什么,我将联系 StellarJs 的创建者,看看它是否是一个错误,或者它是否是出于某种我忽略的原因有意/预期的行为。

The work-around for the height 100% issue can be found here: height: 100% or min-height: 100% for html and body elements?可以在此处找到 height 100% 问题的解决方法: height: 100% 或 min-height: 100% for html 和 body 元素?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM