Coder Social home page Coder Social logo

Comments (2)

acch avatar acch commented on September 28, 2024

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:

  1. 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.

  2. 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 the init() function and providing a new options object, or alternatively by updating the data-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.

acch avatar acch commented on September 28, 2024

I'm closing this one as I have not received any feedback.

from scrollpos-styler.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.