Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Offset by number ignored #15

Open
TheJaredWilcurt opened this issue Oct 29, 2024 · 1 comment
Open

Bug: Offset by number ignored #15

TheJaredWilcurt opened this issue Oct 29, 2024 · 1 comment

Comments

@TheJaredWilcurt
Copy link

Code gets to this point:

      if (this.settings.offset !== null) {
        var offset = 0;

        if (validateSelector(this.settings.offset, this.container)) {
          var offsetElement = this.settings.offset;

          if (typeof offsetElement == 'string') {
            offsetElement = _$(this.settings.offset);
          }

          if (isNodeOrElement(offsetElement)) {
            offset = offsetElement.getBoundingClientRect().height;
          }
        } else if (!isNaN(this.settings.offset)) {
          offset = this.settings.offset;

          if (typeof offset === 'string') {
            offset = parseFloat(offset);
          }
        }

        distFromTop -= offset;

Hits this line if (validateSelector(this.settings.offset, this.container)) {

Which calls validateSelector(500, undefined).

var validateSelector = function validateSelector(selector) {
  var container = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : d;
  var valid = true; // Check if the target is a valid selector inside the scrollToSmooth container

  try {
    if (typeof selector === 'string') {
      _$(selector, container);
    } else if (isNodeOrElement(selector) && container.contains(selector)) {
      selector;
    }
  } catch (e) {
    valid = false;
  }

  return valid;
};

which results in nothing being thrown, so 500 is considered a "valid selector", which means offset gets changed to 0.

@TheJaredWilcurt TheJaredWilcurt changed the title Offset by number ignored Bug: Offset by number ignored Oct 29, 2024
@bfiessinger
Copy link
Owner

Hi @TheJaredWilcurt I couldn't reproduce your issue yet. Can you post your configuration file here so I can have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants