jquery - 恒星 js 不工作

标签 jquery html css parallax

我正在尝试在我的网站上创建视差效果,并且我完全按照 main source 中的说明进行操作。但它仍然无法正常工作。以下是代码片段。

HTML

<div id="home-section" data-stellar-background-ratio="0.5"></div>
<div id="site"></div>

CSS

#home-section {
    background-image: url(inspiration.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;
    width: 100%;
    height: 100vh;
    position: relative;
}
#site {
    height: 4000px;
    width: 100%;
    position: relative;
}

JQ

<script src="js/jquery-3.1.1.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script>
$.stellar();
</script>

这是一个 codepen .

最佳答案

由于不再受支持,Stellar 不能与 jQuery 3.x 一起使用。您应该会在开发工具控制台中看到以下错误(或类似的错误):

Uncaught TypeError: f.getClientRects is not a function

使用 jQuery 2.x 版本,无需任何进一步更改即可运行。

关于jquery - 恒星 js 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44374960/

相关文章:

javascript - PhantomJS:无法通过单击或提交来提交输入

javascript - 如何用javascript在按住鼠标时运行函数

javascript - 如何在 html 中将文本字段输入从 1234567891234 转换为 1234-56-789-1234?

jquery - 从 div 中查找电子邮件而不使用具有电子邮件的 div 的类名

css - 选择具有相同属性值的元素

jquery - 在 jquery mobile 中使用 for 循环将 <li> 添加到 <ul>

css - 如何让头部和 body 颜色不同

html - 将图像与 CSS 对齐

html - 使用iText从html内容到pdf的阿拉伯字符

javascript - JQuery ContextMenu 不适用于多个 id