{"record":{"id":"0c577c81c2604388","repo":"greensock/GSAP","slug":"scrollto-target-doesn-t-exist-using-0","errorCode":null,"errorMessage":"scrollTo target doesn't exist. Using 0","messagePattern":"scrollTo target doesn't exist\\. Using 0","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/ScrollToPlugin.js","lineNumber":50,"sourceCode":"\t},\n\t_clean = (value, index, target, targets) => {\n\t\t_isFunction(value) && (value = value(index, target, targets));\n\t\tif (typeof(value) !== \"object\") {\n\t\t\treturn _isString(value) && value !== \"max\" && value.charAt(1) !== \"=\" ? {x: value, y: value} : {y: value}; //if we don't receive an object as the parameter, assume the user intends \"y\".\n\t\t} else if (value.nodeType) {\n\t\t\treturn {y: value, x: value};\n\t\t} else {\n\t\t\tlet result = {}, p;\n\t\t\tfor (p in value) {\n\t\t\t\tresult[p] = p !== \"onAutoKill\" && _isFunction(value[p]) ? value[p](index, target, targets) : value[p];\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t},\n\t_getOffset = (element, container) => {\n\t\telement = _toArray(element)[0];\n\t\tif (!element || !element.getBoundingClientRect) {\n\t\t\treturn console.warn(\"scrollTo target doesn't exist. Using 0\") || {x:0, y:0};\n\t\t}\n\t\tlet rect = element.getBoundingClientRect(),\n\t\t\tisRoot = (!container || container === _window || container === _body),\n\t\t\tcRect = isRoot ? {top:_docEl.clientTop - (_window.pageYOffset || _docEl.scrollTop || _body.scrollTop || 0), left:_docEl.clientLeft - (_window.pageXOffset || _docEl.scrollLeft || _body.scrollLeft || 0)} : container.getBoundingClientRect(),\n\t\t\toffsets = {x: rect.left - cRect.left, y: rect.top - cRect.top};\n\t\tif (!isRoot && container) { //only add the current scroll position if it's not the window/body.\n\t\t\toffsets.x += _buildGetter(container, \"x\")();\n\t\t\toffsets.y += _buildGetter(container, \"y\")();\n\t\t}\n\t\treturn offsets;\n\t},\n\t_parseVal = (value, target, axis, currentVal, offset) => !isNaN(value) && typeof(value) !== \"object\" ? parseFloat(value) - offset : (_isString(value) && value.charAt(1) === \"=\") ? parseFloat(value.substr(2)) * (value.charAt(0) === \"-\" ? -1 : 1) + currentVal - offset : (value === \"max\") ? _max(target, axis) - offset : Math.min(_max(target, axis), _getOffset(value, target)[axis] - offset),\n\t_initCore = () => {\n\t\tgsap = _getGSAP();\n\t\tif (_windowExists() && gsap && typeof(document) !== \"undefined\" && document.body) {\n\t\t\t_window = window;\n\t\t\t_body = document.body;\n\t\t\t_docEl = document.documentElement;","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/greensock/GSAP/blob/13e2b790546426a1a2e0e9b409f3f8dc6d6611f2/src/ScrollToPlugin.js#L32-L68","documentation":"ScrollToPlugin's _getOffset resolves the scroll target to an element to measure its position. If the passed target (selector or element) resolves to nothing without getBoundingClientRect, it warns \"scrollTo target doesn't exist. Using 0\" and scrolls to offset 0 instead of the intended position.","triggerScenarios":"gsap.to(window, {scrollTo: \"#missing\"}) or scrollTo: {y: \"#el\"} where the selector matches nothing, the element was unmounted, or a null/undefined target value was passed into scrollTo.","commonSituations":"Anchor id typos, elements removed by SPA navigation before the tween runs, tween created before dynamic content rendered, or conditional rendering removing the target section.","solutions":["Verify the target element exists before creating the scrollTo tween","Correct the selector string or pass an Element reference","Re-create the tween after the target element renders (e.g., in useEffect/onMount)","Guard with document.querySelector check before animating"],"exampleFix":"// before\ngsap.to(window, { scrollTo: '#section-3' });\n// after\nconst target = document.querySelector('#section-3');\nif (target) gsap.to(window, { scrollTo: target });\nelse console.warn('scroll target missing');","handlingStrategy":"validation","validationCode":"function resolveScrollTarget(t) {\n  const el = typeof t === 'string' ? document.querySelector(t) : t;\n  if (!(el instanceof Element)) throw new Error(`scrollTo target missing: ${t}`);\n  return el;\n}\ngsap.to(window, { scrollTo: resolveScrollTarget('#section-3') });","typeGuard":"function isElement(v) { return v instanceof Element; }","tryCatchPattern":"try {\n  gsap.to(window, { scrollTo: sel });\n} catch (e) {\n  console.warn('scrollTo skipped:', e.message);\n}","preventionTips":["Resolve and assert the target element before building the tween","Re-create tweens when SPA content re-renders","Avoid hard-coded selector strings scattered across modules"],"tags":["gsap","scrolltoplugin","selector","dom"],"backgroundTag":"element-not-found","analyzedSha":"13e2b790546426a1a2e0e9b409f3f8dc6d6611f2","analyzedAt":"2026-08-29T08:34:05.027Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}