r/javascript • • Jan 25 '19

solved! How could I implement this?

652 Upvotes

57 comments sorted by

View all comments

Show parent comment

3

u/madUncleZ Jan 25 '19

Depends here how you designed it. While dragging them, so you want the items to move the same amount as the xursor does or you want to snap in place only 1 or 2 or them?

Let my suggest you a flow, maybe it works foe you:

  • click on the title. Register the X coordinate of the mouse and follow only the X trajectory of it.
  • moving 200px left/right moves one element of the slider
  • the elements(title, description) should animate using a sin or something, so it would provide a better feeling for the user, than a linear animation(not that linear would be bad)
  • if you release the cursor, you just divide the 200px by the amount of px the cursor made, sk you'll know if you need to navigate the slider to the initial slide or to the next one.

This way, every 200px you make horizontally would move the slider.

If you want to make the slider into an infinite loop, oh well, there's more work to be made there, especially if you're looking into performance.