r/javascript • • Jan 25 '19

solved! How could I implement this?

652 Upvotes

57 comments sorted by

7

u/pseudonick47 Jan 26 '19

Try using coding and algorithms.

5

u/Pixel_Err0r Jan 26 '19

Hmm, any scientific papers on that? I tried looking at the abc conjecture, but I am limited by the technology of my time.

133

u/pomlife Jan 25 '19

55

u/kyerussell Jan 26 '19

Yes. Please. I beg of you. This is some of the most inaccessible UI I've ever seen.

17

u/CCB0x45 Jan 26 '19

Yea it's amazing how much they are used, scrolling down the page is such a better way to feature content.

That being said, there is a good use case for a carousel, such as choosing from a list of options that contain images, i.e. album covers.

7

u/jordanpwalsh Jan 26 '19

I always assumed the devs knew they sucked but were used anyway for ad placement reasons.

1

u/nidarus Jan 27 '19

I prefer to use a flickity-like carousel in those cases, which makes it clear it's a series of images. Which is more of a horizontal scrolling thing, which is often an anti-pattern too, but in this case it's more useful.

Honestly, the only way I'd use the specific kind of carousel they have in that pink, is for "mood" images, and with autoplay enabled. If I have next/prev or a pager, it's only as a backup, for users who liked an item and want to go back. But I don't really except anyone to press them to see more content.

With that said, I'm not sure that OP's design fits that definition either. In my opinion, the fact you can see the headers makes it more of a weird accordion than a carousel.

2

u/nidarus Jan 27 '19

To be fair, what OP has here, is not the same as the carousel in your link. The user isn't completely blind to which content is there, beyond prev/next and the number of pages. You have the titles, that are always visible. And I assume you can also click them, and not just scroll left/right. So it's more of a weird horizontal tabs pattern than a carousel.

Of course, it still trades functionality for flashiness, and even a simple, functional tabbed widget is the wrong choice in many cases. But it's not as thoroughly useless as the carousel in the site you've linked.

1

u/[deleted] Jan 26 '19

I bet my boss will love that website, as every website we have has at least one carousel haha

1

u/rift95 map([🐮, 🥔, 🐔, 🌽], cook) => [🍔, 🍟, 🍗, 🍿] Jan 26 '19

Wow... that's some incredibly poor UX...

-12

u/[deleted] Jan 26 '19

[removed] — view removed comment

13

u/pomlife Jan 26 '19

...what's being shown in the OP is a form of carousel. The problems with carousels do not stem from the fact that they are a library, it stems from the poor analytics and metrics from using them.

-11

u/[deleted] Jan 26 '19

[removed] — view removed comment

12

u/pomlife Jan 26 '19

No one was discussing libraries, but enjoy standing up in that soapbox.

6

u/noruthwhatsoever Jan 26 '19

... a carousel is not a 'library' it's a method of displaying stuff lol

Even if you 'create this form' it will be a carousel lmao

Also you forgot quotes around your class names... lol

35

u/jameshmr Jan 26 '19

Don't. Horrible UX.

8

u/jasonnolanreed Jan 25 '19

I bet https://youtu.be/rBSY7BOYRo4 had some useful tips for what you're trying for

14

u/ThatSpookySJW Jan 25 '19

You can do all of this by toggling classes and CSS transitions

7

u/jasonnolanreed Jan 25 '19

I don't think the draggable aspect can be done by just toggling classes, can it?

8

u/ThatSpookySJW Jan 25 '19

No, I thought they were just clicking. The draggable part has to be done with some finicky js.

2

u/monkeymad2 Jan 25 '19

I think it’s just clicking then following it rather than a drag, it’s not moving at the right speed & at other points it just clicks the title.

1

u/Treolioe Jan 26 '19

You could do it with houdini

1

u/sprazor Jan 26 '19

Right-click the page, then select view source. Copy and paste. Done!

1

u/Pixel_Err0r Jan 26 '19

This is just a prototype made in Adobe XD, so not HTML :/

1

u/sprazor Jan 26 '19

I kid, I kid. Some of these might be helpful https://www.mockplus.com/blog/post/parallax-scrolling-websites I would suggest for desktop browsers at least to use y-scroll.

3

u/qtheginger Jan 26 '19

The way the pointer starts to lag behind the element being dragged bothers me.

1

u/Pixel_Err0r Jan 25 '19

After designing, the fun part begins! What I'm trying to achieve here is a draggable slider with content that displays according to the title. What I have so far is a title wrapper and description wrapper, but I don't even know how to implement swiping. Any thought?

3

u/monkeymad2 Jan 25 '19

It’ve built things like this before - you’ll want to find a library to handle the swipe gesture (not sure what the best one is nowadays) because mouse input / touch handling is really inconsistent between browsers / platforms.

It’d recommend avoiding it if at all possible, preferring normal clicks to gestures.

2

u/ravepeacefully Jan 25 '19

Slick.js is nice

5

u/[deleted] Jan 25 '19 edited Jan 26 '19

React-spring + react-with-gesture: https://twitter.com/0xca0a/status/1081185260208078849

The first handles animation, the latter gets you all the data you need to handle swipes: directions, velocity, deltas, etc.

Live demo for a simple view pager: https://codesandbox.io/embed/n9vo1my91p

1

u/damnloveless Jan 25 '19

Desktop developer, but could you get position of cursor when button is clicked and do some math to determine direction of "swipe" ?

1

u/Pixel_Err0r Jan 25 '19

Good idea, but how could I determine which is the current title? Or at least make them snap?

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.

2

u/damnloveless Jan 25 '19

What type of data structure are these stored in now? Say it was something like an array you could increment the index or decrease to keep track of which title is displaying. Sorry I thought you just meant the UI bit initially. Does this help?

1

u/mlmcmillion Jan 26 '19

Don’t. If people actually use your site, you’re guaranteeing that they’ll hate it the entire time.

1

u/Pixel_Err0r Jan 26 '19

Is it because they have to scroll/swipe a lot to see what's at the end? I'm not that versed in UX...

1

u/mlmcmillion Jan 26 '19

One of the golden rules of the internet (that gets broken far too often) is: Don't mess with scrolling.

First of all, _if_ you manage to get it to work fluidly and bug-free in all browsers (you won't) it's still not the experience users are expecting. It's also not accessible to users using assistive devices.

1

u/Pixel_Err0r Jan 26 '19

Uh-oh... I'm glad I'm still in the designing process... Thanks for pointing that out!

2

u/mlmcmillion Jan 26 '19

Just remember: As web designers/developers/engineers/whatever, our job is to first make the thing accessible and usable, and then pretty.

2

u/sumdumbum19 Jan 25 '19

Here's my 2cents outside of the actual problem mentioned... whatever you implement it with based on the comments made, make sure to throttle the handlers. Mouse movement tracking is expensive (as is scrolling) so by throttling the handlers you get a more performant browser paint.

1

u/tightywhitey Jan 26 '19

A good way to approach this, and any similar mouse handler problem...

Use the onmousemove event, but just store the position and amount the mouse changed to a local property. This is very fast and won't cause problems such as visual stutters. If you need other information just store it as well in this event.

Then add a handler to requestAnimationFrame. This is called when the screen is going to update. Here you would use those previous numbers you stored, do your position calculation, and modify your elements position. Using css translate is a good option for positioning it. This will end up with a really smooth movement.

2

u/almondj Jan 26 '19

A lot of the animation could and arguably should be done with CSS. https://hackernoon.com/in-simple-terms-css-vs-javascript-abc9d709399d

2

u/elbitjusticiero Jan 26 '19

Don't.

It's super annoying.

1

u/oberym Jan 26 '19

Do you want to do it manually? With react-pose you can achieve an effect like that within a few minutes.

1

u/macadeliccc Jan 26 '19

Materializecss or material-ui if you're using react!

1

u/saalejo1986 Jan 26 '19

I'd try to implement it using the transition effect of vuejs as in this example https://vuejs.org/v2/guide/transitions.html

1

u/Edvinoske Jan 26 '19

I did a similar thing yesterday, just used two swiper (search for it on npm) sliders synced to each other.

1

u/fireflypied Jan 26 '19

Horizontal parallax scroller + opacity change based on X

1

u/AustralianBushman Jan 26 '19

I like how my first instinct was to translate this to English

1

u/oompahlumpa Jan 26 '19

I would use Slick slider by Ken Wheeler

0

u/__bogdan Jan 26 '19

Maybe you will never be able to do it...

0

u/[deleted] Jan 25 '19

[deleted]

2

u/sickness29a Jan 25 '19

nice, if OP just add a variation of the opacity on the mouseDown event it will be a perfect match, very nice lib

175

u/[deleted] Jan 25 '19 edited Jan 26 '19

[removed] — view removed comment

0

u/[deleted] Jan 25 '19

[deleted]

7

u/SudoWizard Jan 26 '19

Saving this for later

3

u/mypetocean Jan 26 '19

saving this for later