bind_window_scroll() — svelte Function Reference
Architecture documentation for the bind_window_scroll() function in window.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25["bind_window_scroll()"] 8246ee55_416b_58b3_f7ac_d471f90be1e9["window.js"] 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25 -->|defined in| 8246ee55_416b_58b3_f7ac_d471f90be1e9 e95d0513_ce71_430f_7ef3_577e736f42c1["without_reactive_context()"] 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25 -->|calls| e95d0513_ce71_430f_7ef3_577e736f42c1 7494b934_a3b8_689e_91b6_8435e26461c5["render_effect()"] 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25 -->|calls| 7494b934_a3b8_689e_91b6_8435e26461c5 a985ae40_8ef8_7ef2_adad_116fbf97e70c["effect()"] 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25 -->|calls| a985ae40_8ef8_7ef2_adad_116fbf97e70c 20340432_01a2_6741_abf4_60ccab51cdb3["teardown()"] 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25 -->|calls| 20340432_01a2_6741_abf4_60ccab51cdb3 style 8fa6bd71_c8f4_43c7_f2d8_d71e02986e25 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/internal/client/dom/elements/bindings/window.js lines 10–58
export function bind_window_scroll(type, get, set = get) {
var is_scrolling_x = type === 'x';
var target_handler = () =>
without_reactive_context(() => {
scrolling = true;
clearTimeout(timeout);
timeout = setTimeout(clear, 100); // TODO use scrollend event if supported (or when supported everywhere?)
set(window[is_scrolling_x ? 'scrollX' : 'scrollY']);
});
addEventListener('scroll', target_handler, {
passive: true
});
var scrolling = false;
/** @type {ReturnType<typeof setTimeout>} */
var timeout;
var clear = () => {
scrolling = false;
};
var first = true;
render_effect(() => {
var latest_value = get();
// Don't scroll to the initial value for accessibility reasons
if (first) {
first = false;
} else if (!scrolling && latest_value != null) {
scrolling = true;
clearTimeout(timeout);
if (is_scrolling_x) {
scrollTo(latest_value, window.scrollY);
} else {
scrollTo(window.scrollX, latest_value);
}
timeout = setTimeout(clear, 100);
}
});
// Browsers don't fire the scroll event for the initial scroll position when scroll style isn't set to smooth
effect(target_handler);
teardown(() => {
removeEventListener('scroll', target_handler);
});
}
Domain
Subdomains
Source
Frequently Asked Questions
What does bind_window_scroll() do?
bind_window_scroll() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/elements/bindings/window.js.
Where is bind_window_scroll() defined?
bind_window_scroll() is defined in packages/svelte/src/internal/client/dom/elements/bindings/window.js at line 10.
What does bind_window_scroll() call?
bind_window_scroll() calls 4 function(s): effect, render_effect, teardown, without_reactive_context.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free