Comments (2)
Hi, thanks for your question. Not sure if I fully understand it - please correct me if I'm wrong...
I understand that you're essentially asking for two things:
-
Specify a reference element (by ID) to trigger the styling.
The offset currently has to be specified as a pixel value. A reference element's position (top or bottom offset on page) can be translated into such pixel value using jQuery like you outline above. A similar example using pure JavaScript is described here. -
Dynamically change the offset when the size or position of the reference element changes.
This is difficult to implement inside ScrollPos-Styler, as I don't know which events will change the reference element. Querying the top / bottom offset of the reference element with each scroll event would be a significant waste of resources as most of the time the offset will remain unchanged. Thus, you would need to write your own event handler and inside that handler you should be able to update the offset which ScrollPos-Styler uses. This can either be achieved by calling theinit()
function and providing a new options object, or alternatively by updating thedata-sps-offset
attribute of the element to style. Both should work, please let me know if there's problems with dynamically changing the offset like so.
So what's left is the first part: ability to specify a reference element instead of a pixel value. However, I'm a bit reluctant to implement this as it would make the interface of this script more complex (read: ugly). One would either need to specify a pixel value, or a reference element... What happens if users specify both? Selecting elements by ID only works if you have a single reference element - what if you need multiple offsets for different elements to style? How to decide whether to use the top or bottom offset of the element?
Given the fact that translating an element's position into an offset pixel value is trivial in your own code (see examples above) I'd say that this would be the way to go...
Opinions please?
P.S.: Are you sure that your use case is not addressed by position:sticky
? Does this come close to what you're looking for?
from scrollpos-styler.
I'm closing this one as I have not received any feedback.
from scrollpos-styler.
Related Issues (13)
- General suggestions HOT 2
- No minified version included HOT 4
- Not working correctly when refreshing after scrolling HOT 6
- scrollOffsetY after loading HOT 1
- ES6 How to use ? HOT 6
- Scroll in Firefox HOT 5
- Triggering scrollpos-styler depending of a container scrolling (not Window)
- Bower.json HOT 2
- Offset bottom HOT 5
- Optional Parameters to Customize Class Names HOT 5
- Initialization via options object that's merged with a default one HOT 1
- How to use it to style different elements on the same page? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scrollpos-styler.