Pricing Blog

Keep scrolling position while other things are added on top of it.

  • ssssadsadasd-1407001192856551535

    ssssadsadasd

    10 days ago

    Suppose I have three divs: parent tweets, tweet, children tweets. I come to the page and all tweets are fetched and I scroll to tweet immediately. However, parent tweets have some videos that take some time to load and when they are loaded the height of the parent tweets changes pushing down the postion where I initially scrolled (tweet).

    what I want to achieve is sth [like this](https://vimeo.com/1110966785?share=copy#t=0), where somehow the parent tweets do not push the other divs down but are added on top of them without changing the scrolling positions.

    I created a [sample page](https://editor.nordcraft.com/projects/seno12/branches/start/components/test-scrolling?canvas-width=800&canvas-height=1202.3&selection=onLoad.actions.2.events.tick&rightpanel=style) to illustrate it.

    I would not prefer to solve this using placeholders with a determinate height or getting the height of the video beforehand somehow as this seems too complicated and needs some database additions. and the example in the video seems to not use this anyway

    anyone has any idea how to solve this in nordcraft?

    thanks
  • whitep4nth3r-1407001791240995128

    salma

    10 days ago

    Setting a CSS aspect ratio on the videos should fix this

    https://web.dev/articles/optimize-cls#images-without-dimensions
  • 1407002026910416996-image.png
  • ssssadsadasd-1407003467003728044

    ssssadsadasd

    10 days ago

    @salma thanks but how can I determine the aspect ration if I do not know the video dimensions first? videos can have different dimensions
  • ssssadsadasd-1407003719421395066

    ssssadsadasd

    10 days ago

    if you notice in the video this is not the way it solves this. the parent videos are actually loaded after the target tweet, but the target twee position is not pushed down once the parent tweets are added
  • whitep4nth3r-1407004738129760336

    salma

    10 days ago

    Sorry I didn't watch the video because it required a login 😅
  • If videos have different dimensions then it may be that you need to save that metadata in the database
  • ssssadsadasd-1407005325889900584

    ssssadsadasd

    10 days ago

    hmm it seems to me [the video](https://vimeo.com/1110966785?share=copy#t=0) is public
  • whitep4nth3r-1407005397411303525

    salma

    10 days ago

    1407005397394522184-image.png
  • ssssadsadasd-1407006412806164581

    ssssadsadasd

    10 days ago

    @salma
  • whitep4nth3r-1407007021458522305

    salma

    10 days ago

    if you don't want to save the dimensions or aspect ratio in the database, the only way you prevent layout shift is to do it is with CSS and use aspect ratio.

    It's unclear how the bsky UI solves this because in the video you are not showing the code in the DOM.
  • Using CSS aspect ratio instructs the browser to reserve space for content loading in
  • (or adding height/width dimensions)
  • lucasg-1407009107227049995

    Lucas G

    10 days ago

    Chiming in to say that oftentimes CDNs and CMS used to load in content like this have the item's width, height, and aspect ratio in the payload. They don't just load in a URL for videos/images
    💯1
  • lucasg-1407009934222037115

    Lucas G

    10 days ago

    There's no circumventing having the actual data for this type of stuff. The browser can't guess as to what's going to come in. Other solutions like some very fancy virtual scrolling would be even more complicated to implement
    💯1
  • whitep4nth3r-1407010148504834159

    salma

    10 days ago

    things that "seem too complicated" can often be the right way to do things
  • the backend being a good source of truth and with accurate data to avoid hacky front ends is always a winner
    💯1
  • ssssadsadasd-1407010551732899960

    ssssadsadasd

    10 days ago

    @salma @Lucas G thanks to both. yeah it make sense 👍
    👍1