scrollToSmooth icon indicating copy to clipboard operation
scrollToSmooth copied to clipboard

Bug: Offset by number ignored

Open TheJaredWilcurt opened this issue 1 year ago • 1 comments

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 avatar Oct 29 '24 19:10 TheJaredWilcurt

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

bfiessinger avatar Nov 06 '24 10:11 bfiessinger

I will close this issue for now as there was no response.

bfiessinger avatar Dec 19 '24 12:12 bfiessinger