Jump to content
Search Community

how do I recreate this circular slider?

screencore test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

  • screencore changed the title to how do I recreate this circular slider?

Hi @screencore and welcome to the GreenSock forums!

 

There are a few ways to implement that, some more complex than others. Unfortunately we don't have the time resources to build custom solutions for our users, but we can provide some starting points that help you get started.

 

Take a look at these examples:

See the Pen yLEPvrX by GreenSock (@GreenSock) on CodePen

 

See the Pen BzZOYx by GreenSock (@GreenSock) on CodePen

 

Hopefully these give you enough inspiration to work on your project. Let us know if you have more questions and remember to include a minimal demo.

 

Happy Tweening!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Rodrigo said:

Hi @screencore and welcome to the GreenSock forums!

 

There are a few ways to implement that, some more complex than others. Unfortunately we don't have the time resources to build custom solutions for our users, but we can provide some starting points that help you get started.

thanks for reply. i almost get it done with this example. 

See the Pen QWxOBXx by screencore (@screencore) on CodePen



the only thing is, that i want to show only 3 items in a row.  i wondering if i just can set the opacity to 0 and increase it back to 1 by dragging the item to the center.  maybe i just can add a css class to the element after dragging it to center.

 

Link to comment
Share on other sites

Hi,

 

Setting up something like that is not super trivial.

 

You have elements with fixed widths in px but it's parent has a percentage based width, so you should take into account how to separate them in the initial setup based on the width of the parent and the width of each element. Doing this creates more separation for the cards but, again, that depends on the parent width, so you should look into that in order to find some kind of factor that accounts for the parent's width:

function initCell(element, index) {

  gsap.set(element, {
    // width: cellWidth,
    scale: 0.9,
    opacity:0.5,
    rotation: rotation,
    x: -(cellWidth + 125)
  });

  var tl = gsap.timeline({ repeat: 1 })
    .to(element, 1, { x: "+=" + (wrapWidth + 250), rotation: -rotation}, 0)
    .to(element, cellStep, {scale: 1,opacity:1, repeat: 1, yoyo: true }, 0.5 - cellStep)

  baseTl.add(tl, i * -cellStep);
}

I think you should consider using the MotionPath Plugin as an option:

https://greensock.com/docs/v3/Plugins/MotionPathPlugin

 

Finally I was combing through some Codepen examples and found this:

See the Pen eYEXmJm by GreenSock (@GreenSock) on CodePen

 

I think that should provide more inspiration and a solid starting point for this, all you have to do is replace ScrollTrigger with Draggable.

 

Happy Tweening!

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

10 hours ago, Rodrigo said:

[...] Setting up something like that is not super trivial. [...]

I think you should consider using the MotionPath Plugin as an option:

https://greensock.com/docs/v3/Plugins/MotionPathPlugin

Hey, thanks for your effort. i'll look into the MotionPathPlugin. 
but I'm afraid I didn't make myself clear ;-)

I just want to display 3 items. When dragging they should be faded in and out. Basically i only want to show the ones that have the following css property 
transform: translate3d(750px, 0px, 0px);
transform: translate3d(1000px, 0px, 0px);
transform: translate3d(1250px, 0px, 0px);


so always the one in the middle and the one to the right and left of it .... 

i used to do this with the slick slider and just gave a class to the previous slide. the rest i could solve with css. 

$(this).find('.slick-current').addClass('prev-slide');

so if there is a way to add a css class that would be my solution. but i don't know where that should happen. 

Link to comment
Share on other sites

ok, it's a bit hacky but I#m alomost there ;-)

i just modified the onDragEnd i just need to query if i == 0 etc.

 

onDragEnd: function() {
                const i = wrapIndex(-this.endX / wrapWidth * cells.length - 5);
                console.log(i);

                const _slider = DomAccess.querySelector(document,'.card-slider');
                const _slides = _slider.querySelectorAll('.cell', false);

                Iterator.iterate(_slides,(element,key) => {
                    $(element).removeClass("is-left-slide");
                    $(element).removeClass("is-right-slide");
                    $(element).removeClass("is-current-slide");

                });

                $(_slides[i-2]).addClass("is-left-slide");
                $(_slides[i]).addClass("is-right-slide");
                $(_slides[i-1]).addClass("is-current-slide");

            }

But now I need a function to move the items by click not only drag. what is the best approach?

thank you!

Link to comment
Share on other sites

On 11/18/2022 at 11:12 PM, Rodrigo said:

I think you should consider using the MotionPath Plugin as an option:

https://greensock.com/docs/v3/Plugins/MotionPathPlugin

 

Finally I was combing through some Codepen examples and found this:

 

 

 

I think that should provide more inspiration and a solid starting point for this, all you have to do is replace ScrollTrigger with Draggable.

 

hey @Rodrigo, thanks again. i tried to go with the MotionPathPlugin. unfortunately i can't get the dragable thing to work.  i changed the ScrollTrigger with Dragable but i'm only able to drag the whole wheel but i can't turn it. 

See the Pen yLEpXVz by screencore (@screencore) on CodePen

Could you please give me another hint on how to get there?

thanks in advance

Link to comment
Share on other sites

  • Solution

I don't have much time to dig into this, but perhaps this will help: 

See the Pen zYapWgb?editors=1010 by GreenSock (@GreenSock) on CodePen

 

And I just changed your Draggable type to "rotation" with some snapping and inertia (you need the plugin): 

See the Pen bGKaMbo?editors=1010 by GreenSock (@GreenSock) on CodePen

  • Like 4
Link to comment
Share on other sites

  • 10 months later...

Hi There,

This works great thank you so much. Can we also add next/previous arrows as well? If any one can add that as well that would be awesome. I tried to add it but when I double click the arrow it doesn't calculate the rotation accurately.


 

leftArrow.addEventListener("click", (event) => {
	const myTimeout = setTimeout(() => rotateWheel(1), 500);
});

rightArrow.addEventListener("click", (event) => {
	const myTimeout = setTimeout(() => rotateWheel(-1), 500);
});

function rotateWheel(direction) {
	const totalImages = images.length;
	const angle = (360 / totalImages) * direction;
	

	const currentRotation = gsap.getProperty(".wheel", "rotation");

	const newRotation = currentRotation + angle;

	console.log('testtttt', images.length);

	gsap.to(".wheel", {
		rotation: newRotation,
		duration: images.length,
		ease: "power1.inOut",
		scrollTrigger: {
			start: 0,
			end: "max",
			scrub: 1,
			snap: 1 / images.length,
			invalidateOnRefresh: true
		}
	});
}

Thank you,

Sameer

Screenshot 2023-10-17 190753.png

Link to comment
Share on other sites

Hi @M Sameer and welcome to the GSAP forums!

 

This seems like the simplest approach IMHO:

See the Pen oNJrRgP by GreenSock (@GreenSock) on CodePen

 

Other than that, it'd require to add more custom logic to this example and unfortunately we don't have the time resources for that. Other users though can chime in and try a different approach as well.

 

Hopefully this helps.

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

I wouldn't do it that way because it makes the next/previous buttons inoperable during tweening. Try clicking fast and you'll see that it feels wrong. I'd just use a variable to keep track of the destination value so you can click as much as you want and it still works: 

See the Pen YzdmaeW?editors=0010 by GreenSock (@GreenSock) on CodePen

Link to comment
Share on other sites

  • 3 weeks later...
On 10/18/2023 at 1:34 PM, GreenSock said:

I wouldn't do it that way because it makes the next/previous buttons inoperable during tweening. Try clicking fast and you'll see that it feels wrong. I'd just use a variable to keep track of the destination value so you can click as much as you want and it still works: 

 

 

 

On 10/18/2023 at 1:34 PM, GreenSock said:

I wouldn't do it that way because it makes the next/previous buttons inoperable during tweening. Try clicking fast and you'll see that it feels wrong. I'd just use a variable to keep track of the destination value so you can click as much as you want and it still works: 

 

 

Thank you ! Now it works .

  • 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...