简体   繁体   English

单个元素中的stellar.js

[英]stellar.js in single element

I'm using stellar.js, and i'm with a problem that i dont know if am i using it wrong, or if the plugin isnt working properly... 我正在使用stellar.js,但我遇到的问题是我不知道我使用的是错误的还是插件无法正常工作...

I have an html element 我有一个html元素

<section id="dbr" data-stellar-background-ratio="1.5" rel="dbr">

when i call the stellar plugin like this: 当我像这样调用恒星插件时:

$.stellar({responsive: true});

It works just fine! 它很好用! but its not working when i try it like this: 但是当我这样尝试时它不起作用:

$('#dbr').stellar();

Am i doing something wrong? 难道我做错了什么? thanks! 谢谢!

When initialising Stellar.js, you point it at the element that's scrolling (eg $(window).stellar() , or $.stellar() for short) 初始化Stellar.js时,将其指向正在滚动的元素(例如$(window).stellar()或简称$.stellar()

The reason the first line is working and not the second one is that you're pointing Stellar.js at different elements, when it looks like you need to always point it at window . 第一行工作而不是第二行工作的原因是,您将Stellar.js指向了不同的元素,这时您似乎总是需要将其指向window Your second example would work if it was either $(window).stellar() , or simply $.stellar() . 如果第二个示例是$(window).stellar()或只是$.stellar() ,则第二个示例将起作用。

For Stellar.js to work correctly, it needs to know which element is scrolling so it can keep an eye on the scroll events. 为了使Stellar.js正常工作,它需要知道正在滚动的元素,以便可以密切关注滚动事件。 When initialised, it will automatically search for all parallax elements or backgrounds nested inside. 初始化后,它将自动搜索嵌套在其中的所有视差元素或背景。 So, even if you only have one element, you need to call .stellar() against window . 因此,即使只有一个元素,也需要针对window调用.stellar()

Hope that helps :) 希望有帮助:)

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

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