Круговой слайдер React | @keyframers 4.2 - пример html js css



Книга Круговой слайдер React | @keyframers 4.2

Круговой слайдер React | @keyframers 4.2 (HTML код)


<!--

1. Slide Navigation
2. Slide Animations with CSS Variables
3. Stat Placement on a circle

-->

<div id="root"></div>

<script>
  const slides = [{
      image: "https://images.unsplash.com/photo-1621061415651-2b7fa415360b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMTg4NzkwOQ&ixlib=rb-1.2.1&q=80&w=800&h=800&fit=facearea&facepad=5",
      name: "Lamar J.",
      quote: "Donec nunc ligula, vulputate quis mollis eu, interdum quis libero. Donec nulla ante, facilisis sit amet.",
      stats: [{
          label: "Time",
          value: "~4 years"
        },
        {
          label: "Visits",
          value: "11"
        },
        {
          label: "Funds",
          value: "$2,201"
        },
        {
          label: "Outcome",
          value: "Found housing, employment"
        },
      ]
    },
    {
      image: "https://images.unsplash.com/photo-1621188300102-afe44791fe3b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMTg4ODA2OA&ixlib=rb-1.2.1&q=80&w=800&h=800&fit=facearea&facepad=5",
      name: "Nicole S.",
      quote: "Aliquam eu iaculis mauris. Etiam arcu lectus, imperdiet sit amet volutpat vitae.",
      stats: [{
          label: "Time",
          value: "10 years"
        },
        {
          label: "Visits",
          value: "14"
        },
        {
          label: "Funds",
          value: "$925"
        },
        {
          label: "Outcome",
          value: "Improved health, found employment"
        },
      ]
    },
    {
      image: "https://images.unsplash.com/photo-1551861568-c0afa6653bc1?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMTg4ODU5Ng&ixlib=rb-1.2.1&q=80&w=800&h=800&fit=facearea&facepad=5",
      name: "Pamela W.",
      quote: "Maecenas vestibulum, nulla sed tincidunt viverra, lorem turpis aliquam urna, ut pretium orci purus consequat augue. Etiam a enim orci, vitae pulvinar odio.",
      stats: [{
          label: "Time",
          value: "3 years"
        },
        {
          label: "Visits",
          value: "6"
        },
        {
          label: "Funds",
          value: "$325"
        },
        {
          label: "Outcome",
          value: "Improved health, found housing"
        }
      ]
    },
    {
      image: "https://images.unsplash.com/photo-1603208636525-8825c33ed34b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMTg4ODIzOQ&ixlib=rb-1.2.1&q=80&w=800&h=800&fit=facearea&facepad=5",
      name: "Will K.",
      quote: "Aliquam tempus odio adipiscing diam pellentesque rhoncus. Curabitur a bibendum est.",
      stats: [{
          label: "Time",
          value: "~3 years"
        },
        {
          label: "Visits",
          value: "6"
        },
        {
          label: "Funds",
          value: "$240/mo"
        },
        {
          label: "Outcome",
          value: "Improved health, employment"
        }
      ]
    },
    {
      image: "https://images.unsplash.com/photo-1593339915213-a94e3b1a0f64?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMTg4ODM3OA&ixlib=rb-1.2.1&q=80&w=800&h=800&fit=facearea&facepad=5",
      name: "Barb R.",
      quote: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet.",
      stats: [{
          label: "Time",
          value: "5 years"
        },
        {
          label: "Visits",
          value: "3"
        },
        {
          label: "Funds",
          value: "$240/mo"
        },
        {
          label: "Outcome",
          value: "Found housing, improved health"
        }
      ]
    },
    {
      image: "https://images.unsplash.com/photo-1620506117452-99cd6b6dcd3e?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMTg4ODg0OQ&ixlib=rb-1.2.1&q=80&w=800&h=800&fit=facearea&facepad=5",
      name: "Chuck C.",
      quote: "Etiam a enim orci, vitae pulvinar odio. In elit urna, tincidunt a pellentesque et, scelerisque at nibh. Sed nec est sapien.",
      stats: [{
          label: "Time",
          value: "6 years"
        },
        {
          label: "Visits",
          value: "9"
        },
        {
          label: "Funds",
          value: "$270/mo"
        },
        {
          label: "Outcome",
          value: "Improved health, housing"
        }
      ]
    }
  ];
</script>

<a href="https://youtu.be/xpeNysvnjNQ" target="_blank" data-keyframers-credit style="color: #FFF"></a>
<script src="https://codepen.io/shshaw/pen/QmZYMG.js"></script>

Круговой слайдер React | @keyframers 4.2 (CSS код)



@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@300;500&display=swap");
* {
  position: relative;
  box-sizing: border-box;
}

:root {
  --duration: 0.8s;
  --color-purple: #828dd6;
}

html {
  font-size: clamp(11px, 2vmin, 18px);
}

html,
body {
  height: 100%;
  padding: 0;
  margin: 0;
  font-family: Raleway, sans-serif;
  overflow: hidden;
}

body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: #23274a;
  color: white;
  text-shadow: 0 2px 0 #000;
}

img {
  max-width: 100%;
}

.app {
  display: grid;
  grid-template-columns: 10% 1fr 10%;
  grid-template-rows: 1fr;
}
.app > .dashes {
  margin: -1rem;
  stroke: var(--color-purple);
  stroke-linecap: round;
  stroke-width: 0.6;
  -webkit-animation: rotate 15s linear infinite;
          animation: rotate 15s linear infinite;
}
@-webkit-keyframes rotate {
  to {
    transform: rotate(1turn);
  }
}
@keyframes rotate {
  to {
    transform: rotate(1turn);
  }
}
.app > .dashes,
.app > .slide {
  grid-column: 1/-1;
  grid-row: 1/-1;
}
.app > .button.-next {
  grid-column: -2/-1;
  grid-row: 1/-1;
  align-self: center;
}

.slide {
  padding: 2rem;
  --radius: 35vw;
  width: calc(var(--radius) * 2);
  height: calc(var(--radius) * 2);
  display: grid;
  grid-template-areas: "layer";
  place-items: center;
  --default-animation: fade-in;
  --name-animation: name-enter;
  --image-animation: image-enter;
  --stat-animation: stat-enter;
  --quote-animation: quote-enter;
  --delay: var(--duration);
}
.slide > * {
  grid-area: layer;
  -webkit-animation: var(--default-animation) var(--duration) ease-in-out var(--delay) both;
          animation: var(--default-animation) var(--duration) ease-in-out var(--delay) both;
}
.slide > .slide-name {
  align-self: end;
  z-index: 2;
}
.slide[data-previous] {
  z-index: 2;
  --default-animation: fade-out;
  --name-animation: name-exit;
  --image-animation: image-exit;
  --stat-animation: stat-exit;
  --quote-animation: quote-exit;
  --delay: 0s;
}

@-webkit-keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@-webkit-keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
.slide-name {
  text-align: center;
  font-size: 4.5rem;
  --default-animation: var(--name-animation);
}

.slide-image {
  --default-animation: var(--image-animation);
}

.slide-stat {
  --default-animation: var(--stat-animation);
}

.slide-quote {
  --default-animation: var(--quote-animation);
}

@-webkit-keyframes name-enter {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes name-enter {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
@-webkit-keyframes name-exit {
  from {
    transform: none;
    opacity: 1;
  }
  to {
    transform: translateX(-100%);
    opacity: 0;
  }
}
@keyframes name-exit {
  from {
    transform: none;
    opacity: 1;
  }
  to {
    transform: translateX(-100%);
    opacity: 0;
  }
}
@-webkit-keyframes image-enter {
  from {
    transform: scale(1.2);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
@keyframes image-enter {
  from {
    transform: scale(1.2);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
@-webkit-keyframes image-exit {
  from {
    transform: none;
    opacity: 1;
  }
  to {
    transform: scale(0.7);
    opacity: 0;
  }
}
@keyframes image-exit {
  from {
    transform: none;
    opacity: 1;
  }
  to {
    transform: scale(0.7);
    opacity: 0;
  }
}
@property --r-offset {
  syntax: "";
  inherits: false;
  initial-value: 0turn;
}
@-webkit-keyframes stat-enter {
  from {
    --r-offset: -0.5turn;
    opacity: 0;
  }
}
@keyframes stat-enter {
  from {
    --r-offset: -0.5turn;
    opacity: 0;
  }
}
@-webkit-keyframes stat-exit {
  to {
    --r-offset: -0.3turn;
    opacity: 0;
  }
}
@keyframes stat-exit {
  to {
    --r-offset: -0.3turn;
    opacity: 0;
  }
}
@-webkit-keyframes quote-enter {
  from {
    transform: translate(75%, -150%) scale(0.8);
    opacity: 0;
  }
  to {
    transform: translate(100%, -200%);
    opacity: 1;
  }
}
@keyframes quote-enter {
  from {
    transform: translate(75%, -150%) scale(0.8);
    opacity: 0;
  }
  to {
    transform: translate(100%, -200%);
    opacity: 1;
  }
}
@-webkit-keyframes quote-exit {
  from {
    transform: translate(100%, -200%);
    opacity: 1;
  }
  to {
    transform: translate(75%, -150%) scale(0.8);
    opacity: 0;
  }
}
@keyframes quote-exit {
  from {
    transform: translate(100%, -200%);
    opacity: 1;
  }
  to {
    transform: translate(75%, -150%) scale(0.8);
    opacity: 0;
  }
}
.slide-image {
  border-radius: 100vw;
  box-shadow: 0 0.5rem 2rem #0007;
}

.slide-stat,
.slide-quote {
  --transform: rotate(var(--r)) translate(var(--radius))
    rotate(calc(-1 * var(--r)));
  transform: var(--transform);
}

.slide-quote {
  top: 0;
  left: 0;
  box-shadow: 0 1rem 2rem #000a;
  min-width: 15rem;
}

.slide-stat {
  display: inline-block;
  color: #fff;
  max-width: 16em;
  z-index: 3;
  --d: calc(var(--i) / var(--stats));
  --r-offset: -0.4turn;
  --r: calc(var(--r-offset) + (-0.3turn * var(--d)));
}
.slide-stat:last-of-type {
  --r: calc(var(--r-offset) + 0.45turn);
}

.slide-quote {
  background: linear-gradient(45deg, #23274a, #33396d);
  padding: 1rem;
  font-size: 0.8rem;
  line-height: 1.6;
  max-width: 12em;
  --r: 0.9turn;
}

.stat-label {
  text-transform: uppercase;
  font-size: 0.75rem;
  line-height: 1.5;
  opacity: 0.7;
  letter-spacing: 0.5ch;
  white-space: nowrap;
  font-weight: bold;
}

.stat-value {
  font-size: 2rem;
}

.button {
  z-index: 999999;
  text-transform: uppercase;
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  background: white;
  color: #1b1d3a;
  font-weight: bold;
  height: 12vmin;
  width: 12vmin;
  border-radius: 50%;
  border: none;
  opacity: 0.3;
  transition: opacity 0.3s ease;
  line-height: 1.5;
}
.button:hover {
  cursor: pointer;
  opacity: 1;
}


Круговой слайдер React | @keyframers 4.2 (JS код)



import React, { useState, useMemo } from "https://cdn.skypack.dev/react";
import ReactDOM from "https://cdn.skypack.dev/react-dom";

function Slide({ slide, previous }) {
  return /*#__PURE__*/(
    React.createElement("div", {
      className: "slide",
      style: {
        "--stats": slide.stats.length },

      "data-previous": previous || undefined }, /*#__PURE__*/

    React.createElement("div", { className: "slide-name" }, slide.name), /*#__PURE__*/
    React.createElement("img", { className: "slide-image", src: slide.image }),
    slide.quote && /*#__PURE__*/React.createElement("div", { className: "slide-quote" }, slide.quote),
    slide.stats.map((stat, i) => {
      return /*#__PURE__*/(
        React.createElement("div", {
          className: "slide-stat",
          key: i,
          style: {
            "--i": i } }, /*#__PURE__*/


        React.createElement("div", { className: "stat-label" }, stat.label), /*#__PURE__*/
        React.createElement("div", { className: "stat-value" }, stat.value)));


    })));


}

function App() {
  const [slideIndex, setSlideIndex] = useState(0);
  const [prevSlideIndex, setPrevSlideIndex] = useState(null);
  const activeSlide = useMemo(() => slides[slideIndex], [slideIndex]);
  const prevSlide = useMemo(() => slides[prevSlideIndex], [prevSlideIndex]);

  function nextSlide() {
    setPrevSlideIndex(slideIndex);
    setSlideIndex((slideIndex + 1) % slides.length);
  }

  return /*#__PURE__*/(
    React.createElement("div", { className: "app" }, /*#__PURE__*/
    React.createElement("svg", {
      viewBox: "0 0 100 100",
      className: "dashes",
      fill: "none",
      stroke: "var(--color-purple)",
      "stroke-dasharray": "2 4 4 3 2 3 8 2 3 5" }, /*#__PURE__*/

    React.createElement("circle", { r: "45", cx: "50", cy: "50" })), /*#__PURE__*/

    React.createElement(Slide, { slide: activeSlide, key: slideIndex }),
    prevSlide && /*#__PURE__*/
    React.createElement(Slide, { slide: prevSlide, key: prevSlideIndex + "prev", previous: true }), /*#__PURE__*/

    React.createElement("button", {
      className: "button -next",
      onClick: () => {
        nextSlide();
      } }, "Next", /*#__PURE__*/


    React.createElement("br", null), "Story")));




}

ReactDOM.render( /*#__PURE__*/React.createElement(App, null), document.querySelector("#root"));
//# sourceURL=pen.js
    

Круговой слайдер React | @keyframers 4.2 (Результат кода)

79   0  
    Ничего не найдено.

Добавить ответ:
Отменить.