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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
                <div class="wrapper">
    <div class="box">
      <svg viewbox="0 0 1000 600" class="mask" id="svg-mujer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <defs>
          <mask id="mask-mujer">
            <g fill="white">
              <rect width="100%" height="100%" fill="#555"/>
              <circle class="mask__circle" cx="0" cy="0" r="60"/>
              <circle class="mask__circle" cx="0" cy="0" r="60" fill="none" stroke= "#fff" stroke-width="1%">
                <animate attributeType="SVG" attributeName="r" begin="0s" dur="1.5s" repeatCount="indefinite" from="1%" to="10%"/>
                <animate attributeType="CSS" attributeName="stroke-width" begin="0s" dur="1.5s" repeatCount="indefinite" from="3%" to="0%"/>
                <animate attributeType="CSS" attributeName="opacity" begin="0s" dur="1.5s" repeatCount="indefinite" from="1" to="0"/>
              </circle>
              <text x="50%" y="50%" class="mask__text" dominant-baseline="middle" text-anchor="middle">Mujer</text>
            </g>
          </mask>
        </defs>
        <image width="100%" class="mask__image" xlink:href="https://raw.githubusercontent.com/ivanalbizu/banner-con-animaciones-svg/master/img/mujer.jpg" style="mask: url(#mask-mujer)"/>
      </svg>
      <svg viewbox="0 0 1000 120" class="link" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <a href="#!">
          <text x="50%" y="50%" class="link__text" dominant-baseline="middle" text-anchor="middle">Mujer</text>
        </a>
      </svg>
    </div>
    <div class="box">
      <svg viewbox="0 0 1000 600" class="mask" id="svg-hombre" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <defs>
          <mask id="mask-hombre">
            <g fill="white">
              <rect width="100%" height="100%" fill="#555"/>
              <circle class="mask__circle" cx="0" cy="0" r="60"/>
              <circle class="mask__circle" cx="0" cy="0" r="60" fill="none" stroke= "#fff" stroke-width="1%">
                <animate attributeType="SVG" attributeName="r" begin="0s" dur="1.5s" repeatCount="indefinite" from="1%" to="10%"/>
                <animate attributeType="CSS" attributeName="stroke-width" begin="0s" dur="1.5s" repeatCount="indefinite" from="3%" to="0%"/>
                <animate attributeType="CSS" attributeName="opacity" begin="0s" dur="1.5s" repeatCount="indefinite" from="1" to="0"/>
              </circle>
              <text x="50%" y="50%" class="mask__text" dominant-baseline="middle" text-anchor="middle">Hombre</text>
            </g>
          </mask>
        </defs>
        <image width="100%" class="mask__image" xlink:href="https://raw.githubusercontent.com/ivanalbizu/banner-con-animaciones-svg/master/img/hombre.jpg" style="mask: url(#mask-hombre)"/>
      </svg>
      <svg viewbox="0 0 1000 120" class="link" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <a href="#!">
          <text x="50%" y="50%" class="link__text" dominant-baseline="middle" text-anchor="middle">Hombre</text>
        </a>
      </svg>
    </div>
    <div class="box">
      <svg viewbox="0 0 1000 600" class="mask" id="svg-accesorio" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <defs>
          <mask id="mask-accesorio">
            <g fill="white">
              <rect width="100%" height="100%" fill="#555"/>
              <circle class="mask__circle" cx="0" cy="0" r="60"/>
              <circle class="mask__circle" cx="0" cy="0" r="60" fill="none" stroke= "#fff" stroke-width="1%">
                <animate attributeType="SVG" attributeName="r" begin="0s" dur="1.5s" repeatCount="indefinite" from="1%" to="10%"/>
                <animate attributeType="CSS" attributeName="stroke-width" begin="0s" dur="1.5s" repeatCount="indefinite" from="3%" to="0%"/>
                <animate attributeType="CSS" attributeName="opacity" begin="0s" dur="1.5s" repeatCount="indefinite" from="1" to="0"/>
              </circle>
              <text x="50%" y="50%" class="mask__text" dominant-baseline="middle" text-anchor="middle">Accesorios</text>
            </g>
          </mask>
        </defs>
        <image width="100%" class="mask__image" xlink:href="https://raw.githubusercontent.com/ivanalbizu/banner-con-animaciones-svg/master/img/accesorio.jpg" style="mask: url(#mask-accesorio)"/>
      </svg>
      <svg viewbox="0 0 1000 120" class="link" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <a href="#!">
          <text x="50%" y="50%" class="link__text" dominant-baseline="middle" text-anchor="middle">Accesorios</text>
        </a>
      </svg>
    </div>
    <div class="box">
      <svg viewbox="0 0 1000 600" class="mask" id="svg-perfume" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <defs>
          <mask id="mask-perfume">
            <g fill="white">
              <rect width="100%" height="100%" fill="#555"/>
              <circle class="mask__circle" cx="0" cy="0" r="60"/>
              <circle class="mask__circle" cx="0" cy="0" r="60" fill="none" stroke= "#fff" stroke-width="1%">
                <animate attributeType="SVG" attributeName="r" begin="0s" dur="1.5s" repeatCount="indefinite" from="1%" to="10%"/>
                <animate attributeType="CSS" attributeName="stroke-width" begin="0s" dur="1.5s" repeatCount="indefinite" from="3%" to="0%"/>
                <animate attributeType="CSS" attributeName="opacity" begin="0s" dur="1.5s" repeatCount="indefinite" from="1" to="0"/>
              </circle>
              <text x="50%" y="50%" class="mask__text" dominant-baseline="middle" text-anchor="middle">Perfumes</text>
            </g>
          </mask>
        </defs>
        <image width="100%" class="mask__image" xlink:href="https://raw.githubusercontent.com/ivanalbizu/banner-con-animaciones-svg/master/img/perfume.jpg" style="mask: url(#mask-perfume)"/>
      </svg>
      <svg viewbox="0 0 1000 120" class="link" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <a href="#!">
          <text x="50%" y="50%" class="link__text" dominant-baseline="middle" text-anchor="middle">Perfumes</text>
        </a>
      </svg>
    </div>    
  </div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Montserrat:700&display=swap');
:root {
    --x: -60px;
    --y: -60px;
    --x-close: -60px;
    --y-close: -60px;
}
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body {
    background-color: #000;
}
svg {
    width: 100%;
}
text {
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
}
.wrapper {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    background-color: #0c0c0c;
    max-width: 90%;
    margin: auto;
    .box {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        position: relative;
        overflow: hidden;
    }
}
.mask {
    &__image {
        cursor: none;
    }
    &__circle {
        transform: translate(-120px);
    }
    &__text {
        font-size: 120px;
        text-shadow: 3px 3px 5px #2f2b2b;
    }
    &:hover {
        .mask__circle {
            transform: translate(var(--x), var(--y));
        }
    }
}
.link {
    position: absolute;
    bottom: 0;
    background-color: rgba(0,0,0,.7);

    width: 80%;
    right: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s;
    &__text {
        font-size: 40px;
        fill: #fff;
    }
}
.box--active {
    .mask__image {
        cursor: default;
    }
    .link {    
        opacity: 1;
        visibility: visible;
        transform: translate(0, 0);
        transition: opacity 1s ease-in-out .4s;
    }
}

.circle-click {
    animation-duration: 1.5s;
    animation-fill-mode: forwards;
    animation-name: circle-click;
    pointer-events: none;
}
.circle-click-closing {
    animation-duration: .5s;
    animation-name: circle-click-closing;
}
@keyframes circle-click {
    from {
        r: 60;
    }
    to {
        r: 145%;
    }
}
@keyframes circle-click-closing {
    from {
        r: 145%;
    }
    to {
        cx: var(--x-close);
        cy: var(--y-close);
        r: 0;
    }
}


@media (min-width: 720px) {
    .wrapper {
        .box {
            width: 50%;
        }
    }
}
@media (min-width: 1420px) {
    .wrapper {
        max-width: 76%;
    }
}
            
          
!
            
              document.addEventListener('DOMContentLoaded', () => {
                
    let masks = document.querySelectorAll('.mask');
    masks.forEach(mask => {
        mask.addEventListener('mousemove', handleMove, false)
        mask.addEventListener('click', handleClick, false)
    });
    
    if (/Edge\/\d./i.test(navigator.userAgent)){
        let boxes = document.querySelectorAll('.box');
        boxes.forEach(box => {
            box.style = `
                background-image: url(${box.querySelector('image').getAttribute('xlink:href')});
                background-size: 100%;
                background-position: center;
                cursor: pointer;
            `;
        });
    }
});

const coord = el => {
    let viewportX = el.clientX;
    let viewportY = el.clientY;
    let boxRectangle = el.target.getBoundingClientRect();
    let localX = viewportX - boxRectangle.left;
    let localY = viewportY - boxRectangle.top;

    let x = (localX/boxRectangle.width)*100;
    let y = (localY/boxRectangle.height)*100;

    return {x,y}
}

const handleMove = event => {
    let {x,y} = coord(event);

    let root = document.documentElement;
    root.style.setProperty('--x', `${x}%`);
    root.style.setProperty('--y', `${y}%`);
}

const handleClick = event => {
    const target = event.target;
    const box = target.closest('.box');
    box.classList.toggle('box--active');

    if (box.classList.contains('box--active')) {
        openBox(box);
    } else {
        closeBox(box);
    }    
}

const openBox = (box) => {
    const x = getComputedStyle(document.documentElement).getPropertyValue('--x');
    const y = getComputedStyle(document.documentElement).getPropertyValue('--y');

    const svgns = "http://www.w3.org/2000/svg";
    let newCircle = document.createElementNS(svgns, 'circle');
    newCircle.setAttributeNS(null, 'cx', x);
    newCircle.setAttributeNS(null, 'cy', y);
    newCircle.setAttributeNS(null, 'class', 'circle-click');

    box.querySelector('g').appendChild(newCircle);
}

const closeBox = (box) => {
    let {x,y} = coord(event);
    
    let root = document.documentElement;
    root.style.setProperty('--x-close', `${x}%`);
    root.style.setProperty('--y-close', `${y}%`);

    const elClose = box.querySelector('.circle-click');

    //Elimina el siguiente circle, en caso que fueran muy rápidos
    //los clicks y no diera tiempo con setTimeout a eliminarlos
    //Se usa nextSibling. Si se modifica DOM, habría que cambiar selector
    if (elClose.nextSibling) elClose.nextSibling.remove();
    elClose.classList.add('circle-click-closing');
    elClose.style = `
        cx: ${x};
        cy: ${x};
        r: 0
    `;
    setTimeout(() => {
        elClose.remove();
    }, 500);
}
            
          
!
999px

Console