All Questions
19 questions
0
votes
1
answer
71
views
Svelte:window component onload not triggering
In Svelte5, why is the onload event not triggering the function foo() in src/routers/+layout.svelte?
<script>
const foo = () => console.log('foo triggered')
</script>
<svelte:...
0
votes
2
answers
58
views
Why would my setTimeout() return a random number on screen when the callback function executed
I am trying to learn Svelte by building a quiz app.
What I wanted to achieve is that when the user has answered a question from the quiz, it automatically jumps to the next one. I set a setTimeout() ...
0
votes
1
answer
283
views
svelte create and pass component as html element
I'm using a library which requires me to create an html element and pass that element. Then the library puts the element in the correct place internally.
The problem I'm facing is that the element i ...
1
vote
1
answer
163
views
How do I dynamically render the maximum amount of table rows that will fit within an unknown screen size? Svelte
I'm very new to front end development. I have a table with rows that are each of 52px height. I want to fill the screen with as many rows as possible (and paginate the remainder that don't fit on an ...
0
votes
1
answer
127
views
Download SVG element from page when user clicks
I made a Svelte component, which generates a couple of SVG elements, based on some parameters. I want to provide a download-link or -button for each created SVG element, which saves the SVG code to a ...
1
vote
2
answers
4k
views
window is not defined in svelte - using svelte store
I have a svelte store that has the following code
import { writable } from "svelte/store";
import { onMount, onDestroy } from "svelte";
export const modalStore = () => {
...
1
vote
1
answer
493
views
Javascript and Svelte: updating elements by assignment. When does reactivity work?
Consider the following svelte component
<script>
let x;
$: y = window.innerWidth;
</script>
<svelte.window bind:innerWidth={x} />
<h1>{x}</h1>
<h1>{y}</h1>
&...
-1
votes
2
answers
160
views
Is it possible to hold down element.click for a certain amount of time?
Context: Creating a keyboard element in svelte, i want to emulate a user click to show the animation, but btn.click() is to short to show the transition.
Using btn.click() does fire a click element, ...
0
votes
0
answers
43
views
Why doesn't document.getElementById() work in svelte? [duplicate]
In order to be able to style a File-Upload Button in HTML (technically file input), I need to pass on the buttons click event to the file input. The following code tries to does exactly that. My code ...
1
vote
1
answer
1k
views
How to access offsetTop property of div in reactive variable?
I have the following (simplified) structure:
DIV 1 (changing height because of an accordion)
–––--
DIV 2 (getting pushed down, offsetTop changing accordingly)
I want to assign offsetTop to a reactive ...
0
votes
0
answers
230
views
How to use actions globally in svelte?
I need to traverse the DOM tree for a specific attribute "tooltip". For each element that is found to have this attribute, we'll render a tooltip upon mousemove event on it. If I could make ...
0
votes
1
answer
1k
views
bind svelte elements from {@html} directive
I'm trying to take user input and find all the texts that look something like this
>>523 like imageboards do. I convert these to HTML template strings through the regex replace method and ...
1
vote
3
answers
167
views
Getting into a scrolling loop when shifting DomElements on scroll
I'm building a virtual grid of sorts, that will place content into the viewport as it's required, particularly on user scrolling.
I've been able to achieve this kind of behavior with React, but I seem ...
1
vote
0
answers
71
views
Mouse drag event has Y coordinate jump/gap
Why is there a gap in the drag event?
Here's the working example: https://svelte.dev/repl/e62f83d69cea4fda9e8a897f50b5a67c?version=3.31.1
*Note: the console.logs in the REPL itself slow down the ...
4
votes
0
answers
1k
views
Optimize rendering in Svelte - Adding tens of thousands of DOM elements
I am adding many tens of thousands of elements to the DOM using Svelte but it takes a long time to get to first paint.
This is a toy example:
<script>
const data = Array(100000).fill(0) // 100 ...