Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <div id="root"></div>
<div id="div" class="ac-world-map">
  <?xml version="1.0" encoding="UTF-8"?>
  <svg width="1200px" height="800px" viewBox="0 0 1200 800" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <defs>
      <radialGradient cx="11.0245593%" cy="-0.072%" fx="11.0245593%" fy="-0.072%" r="126.721884%" gradientTransform="translate(0.110246,-0.000720),scale(0.914894,1.000000),translate(-0.110246,0.000720)" id="radialGradient-1">
        <stop stop-color="#FDC300" offset="0%"></stop>
        <stop stop-color="#FF7203" offset="100%"></stop>
      </radialGradient>
      <radialGradient cx="10.92302%" cy="-2.499%" fx="10.92302%" fy="-2.499%" r="130.109%" gradientTransform="translate(0.109230,-0.024990),scale(0.860000,1.000000),translate(-0.109230,0.024990)" id="radialGradient-2">
        <stop stop-color="#FDC300" offset="0%"></stop>
        <stop stop-color="#FF7203" offset="100%"></stop>
      </radialGradient>
    </defs>
    <g id="Artboard" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
      <g id="paths" transform="translate(455.908658, 153.500000)" stroke="#00FFFF" stroke-linecap="square" stroke-width="9">
        <path d="M201.591342,0 C200.556218,20.1808988 200.389551,34.0142322 201.091342,41.5 C202.591342,57.5 200.668374,68.8575416 195.091342,74 C185.656121,82.7000087 162.156121,81.7000087 124.591342,71" id="path-a-c"></path>
        <path d="M203.591342,0 C208.903161,16.1962186 213.903161,28.0295519 218.591342,35.5 C224.316986,44.6236084 233.195726,53.0478675 240.591342,61.5 C265.309777,89.7496407 287.091342,74 297.091342,103 C298.897879,116.247937 293.372121,134.043331 283.091342,148.5 C278.56344,154.867063 269.56344,163.367063 256.091342,174" id="path-a-b"></path>
        <path d="M124.091342,70.5 C116.704051,90.368949 113.370717,104.702282 114.091342,113.5 C115.486338,130.530756 127.068014,148.283387 136.091342,155 C145.250614,161.817804 162.024027,169.818755 187.091342,172 C199.600337,173.088476 222.93367,172.255143 257.091342,169.5" id="path-c-b"></path>
        <path d="M124.091342,72.5 C93.086795,72.8429397 71.4201283,74.8429397 59.0913418,78.5 C28.7805307,87.4910281 5.30918865,107.637306 1.09134185,119.5 C-6.90865815,142 31.1335509,148.367534 48.0913418,175.5 C55.5913418,187.5 61.7624854,202.83841 64.5913418,216.5 C71.8288336,251.452515 70.0913418,285 72.0913418,289.5" id="path-c-e"></path>
        <path d="M256.091342,170.5 C248.424675,200.833333 244.591342,224.666667 244.591342,242 C244.591342,259.333333 246.758009,279.833333 251.091342,303.5" id="path-b-d"></path>
        <path d="M72.0913418,289.5 C88.477298,282.992011 106.310631,280.492011 125.591342,282 C139.400986,283.080084 178.219866,290.472844 205.591342,298 C218.924675,301.666667 234.091342,303.5 251.091342,303.5" id="path-e-d"></path>
        <path d="M72.0913418,289.5 C56.4246752,289.5 44.7580085,293.833333 37.0913418,302.5 C28.0913418,322.5 32.0913418,343.5 35.0913418,360 C37.1787512,371.480751 44.0299729,384.306557 54.5913418,391.5 C67.4867567,400.283183 83.7594245,400.46566 90.5913418,401 C103.532404,402.01215 136.591342,396 159.091342,408 C172.498751,415.150618 187.165418,438.983952 203.091342,479.5" id="path-e-f"></path>
        <path d="M251.091342,303.5 C260.680636,306.35478 267.347302,309.021447 271.091342,311.5 C279.122786,316.816814 284.898512,325.166498 289.091342,331 C300.591342,347 304.091342,363 304.091342,387 C304.091342,393 299.395584,416.104655 294.091342,430 C287.384188,447.570506 276.269803,456.93728 267.091342,465.5 C256.019998,475.828618 234.853332,480.495285 203.591342,479.5" id="path-d-f"></path>
        <path d="M203.591342,479.5 C188.233271,489.212149 175.233271,494.045483 164.591342,494 C153.74589,493.953647 136.82137,494.270904 125.091342,491.5 C111.016616,488.175225 99.8636777,482.863452 90.5913418,478.5 C84.4116027,475.591887 72.5006269,474.75099 63.0913418,476.5 C54.0957563,478.172111 43.0239087,484.811814 40.0913418,487.5 C35.7342384,491.494011 33.0675718,501.494011 32.0913418,517.5" id="path-f-g"></path>
      </g>
      <g id="markers" transform="translate(464.000000, 133.000000)" fill-rule="nonzero">
        <g id="em-a" transform="translate(171.000000, 0.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
        <g id="em-b" transform="translate(224.000000, 169.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
        <g id="em-c" transform="translate(92.000000, 71.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
        <g id="em-d" transform="translate(219.000000, 302.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
        <g id="em-e" transform="translate(40.000000, 288.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
        <g id="em-f" transform="translate(171.000000, 478.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
        <g id="em-g" transform="translate(0.000000, 516.000000)">
          <path d="M47.68,20.94 C47.68,9.78 37.16,0.73 24.18,0.73 C11.2,0.73 0.68,9.78 0.68,20.94 C0.68,21.367 0.7,21.797 0.74,22.23 C0.78,22.663 0.76,23.093 0.68,23.52 C0.68,34.68 11.2,43.73 24.18,43.73 C37.16,43.73 47.68,34.73 47.68,23.52 L47.68,22.23 L47.68,20.94 Z" id="Path" stroke="#FFFFFF" stroke-width="6" fill="url(#radialGradient-1)"></path>
          <ellipse id="Oval" fill="#9B4104" cx="24.18" cy="23.52" rx="23.5" ry="20.21"></ellipse>
          <ellipse id="Oval" stroke="#9B4104" stroke-width="2" fill="url(#radialGradient-2)" cx="24.18" cy="20.94" rx="23.5" ry="20.21"></ellipse>
        </g>
      </g>
      <g id="marks" transform="translate(474.000000, 133.000000)" fill="#000000" font-family="WorkSans-Bold, Work Sans" font-size="36" font-weight="bold">
        <text id="A">
          <tspan x="173" y="33">A</tspan>
        </text>
        <text id="B">
          <tspan x="226" y="202">B</tspan>
        </text>
        <text id="C">
          <tspan x="94" y="103">C</tspan>
        </text>
        <text id="D">
          <tspan x="222" y="335">D</tspan>
        </text>
        <text id="E">
          <tspan x="43" y="321">E</tspan>
        </text>
        <text id="F">
          <tspan x="175" y="512">F</tspan>
        </text>
        <text id="G">
          <tspan x="0" y="549">G</tspan>
        </text>
      </g>
      <g id="avatar" transform="translate(625.000000, 119.000000)">
        <circle id="Oval" fill="#B2DFE8" fill-rule="nonzero" cx="35" cy="35" r="34.5"></circle>
        <path d="M45.9,52.67 L28.59,53 C24.59,53.9 20.17,53 15.5,58.48 C14.62,59.52 13.915,60.695 13.41,61.96 C27.312,73.084 47.396,71.801 59.77,59 C56,54.12 45.9,52.67 45.9,52.67 Z" id="Path" fill="#A7358B" fill-rule="nonzero"></path>
        <circle id="Oval" stroke="#FFFFFF" stroke-width="3" cx="35" cy="35" r="34.5"></circle>
        <path d="M31.9,38.87 C31.9,38.87 34.15,48 32.35,50 C30.55,52 26.3,53.25 26.3,53.25 C26.3,53.25 32.05,59.75 39.4,57.8 C46.75,55.85 48.25,53.3 48.25,53.3 C48.25,53.3 42.7,51.8 41.5,48.95 C40.3,46.1 42.25,40.1 42.25,40.1" id="Path" fill="#E58D51" fill-rule="nonzero"></path>
        <path d="M38.06,49.85 C39.268,49.802 40.455,49.513 41.55,49 C41.546,48.963 41.546,48.927 41.55,48.89 C40.35,46.04 42.3,40.04 42.3,40.04 L31.9,38.87 C31.9,38.87 33.51,45.44 32.9,48.64 C34.506,49.43 36.27,49.844 38.06,49.85 Z" id="Path" fill="#000000" fill-rule="nonzero" opacity="0.16"></path>
        <path d="M31.56,4.45 C26.48,4.45 25.56,7.73 23.01,9.53 C20.46,11.33 17.07,11.2 15.83,12.44 C15.285,12.927 15.107,13.704 15.386,14.38 C15.666,15.055 16.341,15.48 17.07,15.44 C15.64,16.42 13.97,16.998 12.24,17.11 C9.88,17.05 8.71,18.72 10.24,19.77 C11.167,20.41 12.227,20.834 13.34,21.01 C13.34,21.01 10.99,20.7 11.11,22.01 C11.23,23.32 15.26,23.5 15.26,23.5 C15.26,23.5 13.26,23.81 14.39,25.11 C15.52,26.41 18.67,26.84 21.21,26.47 C23.028,26.14 24.795,25.58 26.47,24.8 L39.6,12.8 C40.86,7.93 36.69,4.38 31.6,4.38" id="Path" fill="#0057A3" fill-rule="nonzero"></path>
        <path d="M48.8,30.88 C48.8,39.5 42.9,46.26 37.23,46.1 C31.56,45.94 25.23,39.04 25.23,30.42 C25.23,21.8 29.11,14.73 37.23,14.89 C46.02,15.06 48.8,22.27 48.8,30.89 L48.8,30.88 Z" id="Path" fill="#E58D51" fill-rule="nonzero"></path>
        <path d="M48.28,27.65 C48.28,27.65 51.35,26.87 51.51,30.94 C51.677,31.924 51.352,32.928 50.641,33.63 C49.931,34.33 48.922,34.64 47.94,34.46 L48.28,27.65 L48.28,27.65 Z M25.63,27.65 C25.63,27.65 22.56,26.87 22.39,30.94 C22.22,31.933 22.548,32.946 23.27,33.65 C23.99,34.352 25.012,34.656 26,34.46 L25.67,27.65 L25.63,27.65 L25.63,27.65 Z" id="Shape" fill="#E58D51" fill-rule="nonzero"></path>
        <path d="M25.6,30.81 C26.069,27.796 26.737,24.816 27.6,21.89 C28.53,19.47 30.81,17.05 37.06,17.05 C43.31,17.05 45.81,19.78 46.56,22.32 C47.31,24.86 48.23,30.43 48.23,30.43 C48.23,30.43 49.84,27.59 48.91,22.43 C47.98,17.27 44.91,11.66 37.27,11.78 C29.63,11.9 26.8,15.68 25.62,20.45 C24.884,23.86 24.884,27.39 25.62,30.8 L25.6,30.81 Z" id="Path" fill="#0057A3" fill-rule="nonzero"></path>
        <path d="M33.5,30.35 C33.5,30.8 33.01,31.03 32.5,31.05 C31.99,31.07 31.5,30.41 31.5,29.95 C31.5,29.49 31.99,29.42 32.5,29.4 C33.014,29.446 33.428,29.84 33.5,30.35 L33.5,30.35 Z M43.3,30 C43.3,30.45 42.81,31.14 42.35,31.15 C41.89,31.16 41.35,30.96 41.35,30.5 C41.4,29.988 41.791,29.576 42.3,29.5 C42.75,29.53 43.29,29.58 43.3,30 Z" id="Shape" fill="#000000" fill-rule="nonzero"></path>
        <path d="M29.33,26.94 L33.77,26.3 M41.01,25.18 L45.18,26.85" id="Shape" stroke="#000000" stroke-width="0.9" stroke-linecap="round" stroke-linejoin="round"></path>
        <path d="M33.35,38.56 C33.35,39.88 34.95,40.96 36.93,40.97 C38.91,40.98 40.53,39.97 40.53,38.6 C40.53,37.23 39.05,38.6 37.06,38.6 C35.07,38.6 33.36,37.24 33.35,38.56 Z" id="Path" fill="#FFFFFF" fill-rule="nonzero"></path>
      </g>
    </g>
  </svg>
</div>
              
            
!

CSS

              
                $background-image: "https://i.ibb.co/XCfxJHN/worldmap-background-1x.webp";

html {
  font-size: 62.5%;
}

html,
body {
  position: relative;
  width: 100vw;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: black;

  color: black;

  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-size: 1.8rem;

  * {
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
}

@mixin disable-appearance($value: none) {
  -webkit-appearance: $value;
  -moz-appearance: $value;
  appearance: $value;
}

@mixin prevent-highlight() {
  outline: none;
  outline: 0;
  outline-color: rgba(0, 0, 0, 0);
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-tap-highlight-color: transparent;
}

.ac-world-map {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  width: 120rem;
  height: 99.8rem;
  margin: 0 auto;

  background: transparent;
  background-image: url($background-image);
  background-repeat: no-repeat;
  background-position: top center;
  background-size: 120rem auto;

  svg {
    g[id^="em-"] {
      cursor: pointer;
    }

    #marks *,
    #paths *,
    #avatar {
      pointer-events: none;
      @include prevent-highlight;
      @include disable-appearance;
    }
  }
}

              
            
!

JS

              
                // Register GSAP plugin
gsap.registerPlugin(MotionPathPlugin);

const AcUUID = (prefix) => {
  let characters =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  let text = "";

  for (let i = 0; i < 12; i++) {
    text += characters.charAt(Math.floor(Math.random() * characters.length));
  }

  if (prefix) text = prefix + "-" + text;

  return text;
};

let animations = {};
let instance = {
  location: "a",
  anim: null
};

const AcWorldMap = ({}) => {
  React.useEffect(() => {
    init();
  }, []);

  const init = async () => {
    await addTweens();
    await addEvents();

    instance.anim = gsap.to({}, {});
  };

  const generateTween = (path_id, path_d, reverse = false) => {
    const id = AcUUID();

    const anim = gsap.to("#avatar", {
      id,
      motionPath: {
        path: path_d,
        align: path_id,
        alignOrigin: [0.5, 0.5]
      },
      transformOrigin: "50% 50%",
      duration: 1,
      ease: "none",
      paused: true,
      reversed: false
    });

    return anim;
  };

  const addTweens = () => {
    return new Promise((resolve) => {
      const $paths = document.querySelectorAll('path[id^="path-"]');

      let n = 0;
      const len = $paths.length;

      for (n; n < len; n++) {
        const $el = $paths[n];
        const id = $el.getAttribute("id");
        const d = $el.getAttribute("d");
        const arr = id.split("-");
        const from = arr[1];
        const to = arr[2];

        const anim = generateTween(id, d);

        if (!animations[from]) animations[from] = {};
        if (animations[from]) {
          animations[from][to] = {
            id: AcUUID(),
            from,
            to,
            anim,
            reverse: false
          };
        }

        if (!animations[to]) animations[to] = {};
        if (animations[to]) {
          animations[to][from] = {
            id: AcUUID(),
            from: to,
            to: from,
            anim,
            reverse: true
          };
        }
      }

      resolve();
    });
  };

  const play = React.useCallback(
    (location) => {
      const case1 = instance.anim && instance.anim.isActive();
      const case2 = instance.location === location;
      const case3 =
        !animations[instance.location] ||
        !animations[instance.location][location];

      if (case1 || case2 || case3) return;

      const obj = animations[instance.location][location];

      instance = {
        location,
        anim: obj.reverse ? obj.anim.progress(1).reverse() : obj.anim.play()
      };
    },
    [instance]
  );

  const handleMarkerClick = React.useCallback(
    ($marker) => {
      const id = $marker.getAttribute("id");
      const arr = id.split("-");
      const location = arr[1];

      play(location);
    },
    [instance]
  );

  const addEvents = () => {
    return new Promise((resolve) => {
      const $markers = document.querySelectorAll('g[id^="em-"]');

      let n = 0;
      const len = $markers.length;

      for (n; n < len; n++) {
        const $m = $markers[n];

        $m.addEventListener(
          "click",
          (event) => {
            if (event && event.stopPropagation) event.stopPropagation();
            handleMarkerClick($m);
          },
          false
        );
      }
      resolve();
    });
  };

  return null;
};

ReactDOM.render(<AcWorldMap />, document.getElementById("root"));

              
            
!
999px

Console