Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src='https://unpkg.co/gsap@3/dist/gsap.min.js'></script>
    <script src='https://unpkg.com/gsap@3/dist/Draggable.min.js'></script>
    <script src='https://assets.codepen.io/16327/InertiaPlugin.min.js'></script>
    <script
            src="https://code.jquery.com/jquery-3.6.3.js"
            integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM="
            crossorigin="anonymous"></script>
</head>
<body>
<div class="container">

    <div class="wrapper">

        <div class="content">
            <div class="track">
                <div class="center"></div>
            </div>
            <div class="item active"><div class="child">1</div></div>
            <div class="item left left-0"><div class="child">2</div></div>
            <div class="item left left-1"><div class="child">3</div></div>
            <div class="item left left-2"><div class="child">4</div></div>
            <div class="item centered"><div class="child">5</div></div>
            <div class="item right right-0"><div class="child">6</div></div>
            <div class="item right right-1"><div class="child">7</div></div>
            <div class="item right right-2"><div class="child">8</div></div>
        </div>

    </div>
    <div class="descriptions">
        <div class="title">TITLE 1</div>
        <div class="title">TITLE 2</div>
        <div class="title">TITLE 3</div>
        <div class="title">TITLE 4</div>
        <div class="title">TITLE 5</div>
        <div class="title">TITLE 6</div>
        <div class="title">TITLE 7</div>
        <div class="title">TITLE 8</div>
    </div>
</div>

</body>
</html>
              
            
!

CSS

              
                 body {

        margin: 0;
        padding: 0;
        position: relative;
    }
    .container {
        box-sizing: border-box;
        position: relative;
        width: 100%;
        height: auto;
        padding: 0;
        margin: 0;
        overflow: hidden;
        padding: 50px;
    }
    .wrapper {
        position: relative;
        width: 100%;
        max-width: 500px;
        height: auto;
        margin: 0 auto;
        padding: 0;
    }
    #path-svg {
        position: relative;
        width: 100%;
        height: auto;
        z-index: 1;
    }
    .content {
        position: relative;
        top: 0;
        left: 0;
        /*width: 100%;*/
        /*height: 0;*/
        overflow: visible;
        /*padding-bottom: 84%;*/
        z-index: 2;

    }

    .content::before {
        float: left;
        padding-top: 84%;
        content: "";
    }

    .content::after {
        display: block;
        content: "";
        clear: both;
    }
    .track {
        border-radius: 50%;
        position: absolute;
        width: 100%;
        height: 100%;
    }

    .item {
        width: 75px;
        height: 75px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        /*background-color: #708a91;*/
        transition: all 0.3s ease;
    }

    .item:before{
        content:'';
        width: 2px;
        height: 100px;
        display: block;
        background-color: blue;
        left: 50%;
        position: absolute;
    }
    .item .child {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        margin: auto;
        width: 100%;
        height: 100%;
        color: #fee3c9;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .item .child{
        width: 26px;
        height: 26px;
        background: orange;
        border-radius: 50%;
    }
    .descriptions {
        /*  position: absolute;*/
        text-align: center;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 3;
        pointer-events: none;
    }
    .title {
        top: 50px;
        left: 50%;
        transform: translateX(-50%);
        width: fit-content;
        height: auto;
        font-size: 20px;
    }
    .title.active {
        opacity: 1;
    }
    .item.active {
        background-color: red;
        top: 60%;
        left: 50%;
    }
    @media (max-width: 799px) {
        .wrapper {
            max-width: 360px;
        }
    }
    /*.item:nth-child(odd){
        left: 40%;
    }*/
    .center{
        width: 108px;
        height: 108px;
        background: red;
        border-radius: 50%;
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        z-index: 9;
        bottom: 0;
        margin: auto;
    }
    /*.centered{*/
    /*    width: 13px;*/
    /*    height: 13px;*/
    /*    top: 60%;*/
    /*}*/
    /*.item:before{*/
    /*    content: '';*/
    /*    width: 1px;*/
    /*    height: 100%;*/
    /*    display: block;*/
    /*    background: red;*/
    /*    left: 50%;*/
    /*    position: absolute;*/
    /*    bottom: 0px;*/
    /*}*/
    /*.centered:before{*/
    /*    bottom: -13px;*/
    /*}*/
    .item:before{
        transition: all 0.6s ease;
    }

.item.left-0:before{
    bottom: 12px;
    transform: rotate(45deg);
    left: 86%;
}
.item.left-2:before{
    left: 100%;
    bottom: -81%;
    transform: rotate(140deg);
}
.item.centered:before{
    top: 50%;
    transform: rotate(180deg);
}
.item.left-1:before{
      transform: rotate(90deg);
    left: 162%;
    bottom: -18%;
}
.item.right-0:before{
    top: 38%;
    transform: rotate(228deg);
    left: -10%;
}
.item.right-1:before{
    top: -15%;
    transform: rotate(270deg);
    left: -22%;
}
.item.right-2:before{
    top: -81%;
    transform: rotate(317deg);
    left: -21%;
}
.item.active:before{
    bottom: 48px;
}
.item.right-0 .child{
  left: -30px;
    top: 30px;
}
.item.right-2 .child{
    left: -38px;
    top: -24px;
}
.item.left-1 .child{
  left: 52px;
}
              
            
!

JS

              
                  gsap.registerPlugin(Draggable, InertiaPlugin);

    let descriptions = gsap.utils.toArray(".descriptions .title");
    $('.title').not(':first').hide();
    let items = gsap.utils.toArray(".content .item");
    let carousel = buildCarousel(items, {
        radiusX: 110,
        radiusY: 110,
        activeAngle: -270,
        draggable: true,
        autoAdvance: false,
        onClick(element, self) {
            self.to(element, {duration: 2, ease: "power1.inOut"}, "short");
        },
        onActivate(element, self) {
            element.classList.add("active");
            $(".content .item").removeClass("left right centered left-0 left-1 left-2 right-0 right-1 right-2");
            var l = [];
            var r = [];
            var flagFirst = false;
            var i = $('.active').index();
            while(l.length<3 || r.length<3){
                if(i>=8){
                    i = 0
                }
                if(l.length<3){
                    l.push(items[i]);
                }else{
                    if(!flagFirst){
                        $(items[i]).addClass('centered');
                        flagFirst = true
                    }else{
                        r.push(items[i]);
                    }

                }
                i++
            }
            $.each(l,function(ind,elem){
                $(elem).addClass(`left left-${ind}`)
            })
            $.each(r,function(ind,elem){
                $(elem).addClass(`right right-${ind}`)
            })
            console.log(r)

        },
        onDeactivate(element, self) {
            element.classList.remove("active");
        },
        // when a drag or animation starts (via the Carousel's to()/next()/previous() methods)
        onStart(element, self) {
            $('.title').hide();
            // gsap.to(descriptions[items.indexOf(element)], {autoAlpha: 0, duration: 0.25, overwrite: "auto"});
        },
        onStop(element, self) {
            $(descriptions[items.indexOf(element)]).css('display','block')
        }
    });

    // document.querySelector(".next").addEventListener("click", () => carousel.next());
    // document.querySelector(".previous").addEventListener("click", () => carousel.previous());


    // example of resizing
    // let mm = gsap.matchMedia();
    // mm.add("(min-width: 800px)", () => { // desktop
    //     carousel.resize(110, 110);
    // });
    //
    // mm.add("(max-width: 799px)", () => { // mobile
    //     carousel.resize(110, 110);
    // });



    /*
    Setup: place all the targets on top of each other, position: absolute, and then pass them in to this helper function and it'll spread them out from their starting position as if that's the origin.
    The config object (2nd parameter) can have any of the following optional properties:

    - radiusX: Number - radius (in pixels) on the x-axis
    - radiusY: Number - radius (in pixels) on the y-axis
    - activeAngle: Number - angle (in degrees) that's considered the "active" spot (defaults to -90 meaning the 12 o'clock position). 0 would be on the far right side. 90 would be bottom, etc.
    - activeElement: Element | String - the element that should initially be active
    - autoAdvance: Number [optional] - number of seconds between next() calls
    - onActivate: Function - called when a new element is considered the "active" one (closest to the active slot). The first parameter is the active element, the second is the Carousel instance itself.
    - onDeactivate: Function - called when an element goes from being the active one to NOT the active one. The first parameter is the formerly active element, the second is the Carousel instance itself.
    - onClick: Function - called when an element is clicked
    - onStart: Function - called when a drag or animation starts (via the Carousel's to()/next()/previous() methods)
    - onStop: Function - called when a drag or animation stops (via the Carousel's to()/next()/previous() methods);
    - draggable: Boolean - if true, the carousel will be draggable. Don't forget to load Draggable and InertiaPlugin

    An object gets returned that has the following methods:

    - rotation() - a getter/setter for the rotation (in degrees) of the overall carousel.
    - activeElement() - returns the currently active element (the one closest to the "active" slot)
    - elementRotation() - pass in an element and it'll return the rotation of the carousel corresponding to when that particular element is active
    - to() - lets you animate to a particular element or rotation and you get total control of that animation by using the vars and direction parameters. Method signature:
            - elementOrRotation: Element | String | Number - the destination element or rotation value
            - vars: Object - configuration object for the tween, just like any gsap.to() vars object so you can define duration, ease, onComplete, whatever.
            - direction: String [optional] - "short" goes in the shortest direction, "cw" goes in the clockwise direction, and "ccw" goes in the counter-clockwise direction.
    - next() - goes to the next element. You can pass in a vars object and direction if you'd like to control the animation
    - previous() - goes to the previous element. You can pass in a vars object and direction if you'd like to control the animation
    - resize(radiusX, radiusY) - for resizing
    - kill() - kills the carousel, cleaning up event listeners, etc.
     */
    function buildCarousel(targets, {radiusX = 200, radiusY = 200, activeAngle = -90, activeElement, onClick, onActivate, onDeactivate, onStart, onStop, draggable, autoAdvance}) {
        targets = gsap.utils.toArray(targets);
        gsap.set(targets, {xPercent: -50, x: 0, yPercent: -50, y: 0});
        let DEG2RAD = Math.PI / 180,
            eventTypes = ("ontouchstart" in document.documentElement ? "touchstart,touchmove,touchcancel,touchend" : !("onpointerdown" in document.documentElement) ? "mousedown,mousemove,mouseup,mouseup" : "pointerdown,pointermove,pointercancel,pointerup").split(","),
            round = value => Math.round(value * 10000) / 10000,
            tempDiv = document.createElement("div"),
            quantity = targets.length,
            angleInc = 360 / quantity,
            wrap = gsap.utils.wrap(0, quantity),
            angleWrap = gsap.utils.wrap(0, 360),
            rotation = 0,
            dragged,
            onPressRotation,
            autoAdvanceCall = autoAdvance && gsap.delayedCall(parseFloat(autoAdvance) || 2, () => { self.next(); autoAdvanceCall.restart(true); }),
            xSetters = targets.map(el => gsap.quickSetter(el, "x", "px")),
            ySetters = targets.map(el => gsap.quickSetter(el, "y", "px")),
            self = {
                rotation(value) {
                    if (arguments.length) {
                        let prevActive = activeElement;
                        rotation = angleWrap(value);
                        activeElement = targets[wrap(Math.round(-value / angleInc))];
                        self.render();
                        if (prevActive !== activeElement) {
                            onDeactivate && prevActive && onDeactivate(prevActive, self);
                            onActivate && onActivate(activeElement, self);
                        }
                    }
                    return rotation;
                },
                resize(rx, ry) {
                    radiusX = rx;
                    radiusY = ry;
                    self.render();
                },
                render() {
                    let inc = angleInc * DEG2RAD,
                        a = (rotation + activeAngle) * DEG2RAD,
                        i = 0;
                    for (; i < quantity; i++) {
                        xSetters[i](round(Math.cos(a) * radiusX));
                        ySetters[i](round(Math.sin(a) * radiusY));
                        a += inc;
                    }
                },
                activeElement(value) {
                    if (arguments.length) {
                        self.rotation(self.elementRotation(value));
                    }
                    return activeElement;
                },
                elementRotation(element) {
                    let index = targets.indexOf(gsap.utils.toArray(element)[0]);
                    return (quantity - index) * angleInc;
                },
                to(elOrRotation, vars, direction) {
                    vars = vars || {};
                    vars.rotation = typeof(elOrRotation) === "number" ? elOrRotation : (self.elementRotation(elOrRotation) || parseFloat(elOrRotation));
                    vars.overwrite = true;
                    let { onUpdate, onComplete } = vars,
                        _onStart = vars.onStart;
                    autoAdvanceCall && autoAdvanceCall.pause();
                    vars.onStart = function() {
                        onStart && onStart(activeElement, self);
                        _onStart && _onStart.call(this);
                    }
                    vars.onComplete = function() {
                        onStop && onStop(activeElement, self);
                        onComplete && onComplete.call(this);
                        autoAdvanceCall && autoAdvanceCall.restart(true);
                    };
                    if (direction) {
                        let getter = gsap.getProperty(tempDiv);
                        vars.onUpdate = function() {
                            self.rotation(getter("rotation"));
                            onUpdate && onUpdate.call(this);
                        }
                        vars.rotation += "_" + direction;
                        return gsap.fromTo(tempDiv, {rotation: rotation}, vars);
                    }
                    return gsap.to(self, vars);
                },
                next(vars, direction) {
                    let element = targets[wrap(targets.indexOf(activeElement) + 1)];
                    self.to(element, vars, direction || "ccw");
                },
                previous(vars, direction) {
                    let element = targets[wrap(targets.indexOf(activeElement) - 1)];
                    self.to(element, vars, direction || "cw");
                },
                kill() {
                    targets.forEach(el => {
                        el.removeEventListener("click", _onClick);
                        el.removeEventListener(eventTypes[0], onPress);
                        el.removeEventListener(eventTypes[2], onRelease);
                        el.removeEventListener(eventTypes[3], onRelease);
                    });
                    gsap.killTweensOf(self);
                    tempDiv.parentNode && tempDiv.parentNode.removeChild(tempDiv);
                    autoAdvanceCall && autoAdvanceCall.kill();
                    draggable && draggable.kill();
                },
                autoAdvance: autoAdvanceCall
            },
            _onClick = e => {
                if (!dragged) {
                    autoAdvanceCall && autoAdvanceCall.restart(true);
                    onClick && onClick(e.currentTarget, self);
                }
            },
            onPress = e => {
                onPressRotation = rotation;
                gsap.set(tempDiv, {rotation: rotation});
                autoAdvanceCall && autoAdvanceCall.pause();
                gsap.killTweensOf(self);
                draggable.startDrag(e);
                dragged = false;
            },
            onRelease = e => {
                draggable.endDrag(e);
                if (rotation === onPressRotation) {
                    autoAdvanceCall && autoAdvanceCall.restart(true);
                    draggable.tween && draggable.tween.kill();
                    _onClick(e);
                }
            },
            syncDraggable = () => {
                if (!dragged) {
                    onStart && onStart(activeElement, self);
                    dragged = true;
                }
                self.rotation(draggable.rotation);
            };
        targets[0].parentNode.appendChild(tempDiv);
        gsap.set(tempDiv, {visibility: "hidden", position: "absolute", width: 0, height: 0, top: "50%", left: "50%", xPercent: -50, yPercent: -50});
        targets.forEach(el => {
            if (draggable) {
                el.addEventListener(eventTypes[0], onPress);
                el.addEventListener(eventTypes[2], onRelease);
                el.addEventListener(eventTypes[3], onRelease);
            } else {
                el.addEventListener("click", _onClick);
            }
        });

        self.snap = angleInc;
        draggable && (self.draggable = draggable = Draggable.create(tempDiv, {type: "rotation", snap: gsap.utils.snap(angleInc), inertia: true, onThrowComplete: () => {autoAdvanceCall && autoAdvanceCall.restart(true); onStop && onStop(activeElement, self)}, onThrowUpdate: syncDraggable, onDrag: syncDraggable})[0])
        self.activeElement(gsap.utils.toArray(activeElement)[0] || targets[0]);
        return self;
    }
              
            
!
999px

Console