Jump to content
Search Community

Poor performance of <video> elements inside of draggable

SeanAye test
Moderator Tag

Go to solution Solved by ZachSaucier,

Recommended Posts

I am using draggable as a replacement for the css scroll-snap property since it supports snapping to a specific location and it works great.

The child elements of the draggable are video elements which played fine before but since introducing draggable they are very choppy/laggy.

How can I improve the playback performance of the video elements?  Please see attached vimeo link for context.

 

EDIT: this is specifically an issue on devices with slower GPU performance. Devices with strong GPU's don't have this issue

 

const drag = Draggable.create('#scroller', {
  type: 'scroll',
  throwProps: true,
  snap: (endValue) => {
    const curHeight = -state.currentIndex * state.snapHeight
    console.log({ endValue, curHeight })
    if (endValue < (curHeight)) { // scrolling values are negative/going down
      console.log('if condition')
      return (state.currentIndex + 1) * state.snapHeight
    } else {
      console.log('else condition')
      return (state.currentIndex - 1) * state.snapHeight
    }
  },
  force3D: true,
  inertia: true,
  onThrowComplete: () => {
    state.currentIndex = state.mostRecentObseravtion
  },
  maxDuration: 0.5
})

 

Link to comment
Share on other sites

  • Solution

Hey Sean and welcome to the GreenSock forums.

 

Most likely there's nothing you can do on the GSAP side to improve performance. GSAP is very optimized :) 

 

I'm guessing if you add will-change: transform to whatever is being dragged that'd help. Hard to give help past that. 

Link to comment
Share on other sites

I wasn't even aware of this css property. After a quick check this seems to have solved it. Although according to MDN this property should only be used as a last ditch effort. I'm open to trying other suggestions which would be considered 'better practice' at least as far as MDN is concerned.

 

Thank you Zach~!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...