Copy environment

Cursor Pet

<div class="cursor-pet" data-drag="drag" data-view="view" data-close="close">
    <div class="cursor-pet__inner">
        <div class="cursor-pet__label"></div>
    </div>
</div>
<div class="cursor-pet" data-drag="{{ data.dragLabel }}" data-view="{{ data.viewLabel }}" data-close="{{ data.closeLabel }}">
    <div class="cursor-pet__inner"><div class="cursor-pet__label"></div></div>
</div>
{
  "language": "en-US",
  "data": {
    "viewLabel": "view",
    "dragLabel": "drag",
    "closeLabel": "close"
  }
}
  • Content:
    .cursor-pet {
        position: fixed;
        top: 0;
        left: 0;
        z-index: map_get($zindex, cursor-pet);
        transition-property: transform;
        transition-duration: $transition-duration*2;
        transition-timing-function: $transition-easing-cursor;
        pointer-events: none;
        will-change: transform; /* stylelint-disable-line plugin/no-unsupported-browser-features */
    }
    
    .cursor-pet__inner {
        width: 12px;
        height: 12px;
        background: rgba($color-text-03, 1);
        border-radius: $border-radius-round;
        transition-property: background, width, height;
        transition-duration: $transition-duration;
        transition-timing-function: $transition-easing-in;
        transform: translate3d(-50%, -50%, 0);
    
        .cursor-pet.is-dark & {
            background: rgba($color-brand-01, 1);
            transition-timing-function: $transition-easing-out;
        }
    
        .cursor-pet.is-hover & {
            width: 48px;
            height: 48px;
            background: rgba($color-text-03, .3);
            transition-timing-function: $transition-easing-out;
        }
    
        .cursor-pet.is-hover.is-dark & {
            background: rgba($color-brand-01, .3);
        }
    
        .cursor-pet.is-text & {
            width: 60px;
            height: 60px;
        }
    
        .cursor-pet.is-hover.is-dark.is-modal & {
            background: rgba($color-text-03, .4);
        }
    }
    
    .cursor-pet__label {
        font-size: $font-size-tiny;
        line-height: $line-height-tiny;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: $color-brand-01;
        opacity: 0;
        transition-property: opacity;
        transition-duration: $transition-duration;
        transition-timing-function: $transition-easing-in;
    
        .cursor-pet.is-text & {
            opacity: 1;
            transition-timing-function: $transition-easing-out;
        }
    
        .cursor-pet.is-dark & {
            color: $color-text-03;
        }
    }
    
  • URL: /components/raw/cursor-pet/cursor-pet.scss
  • Filesystem Path: src/patterns/components/cursor-pet/cursor-pet.scss
  • Size: 1.8 KB
  • Content:
    import whatInput from 'what-input';
    
    import Component from '../component/component';
    import Helpers from '../helpers/helpers';
    
    import './cursor-pet.scss';
    
    import MouseMoveEvent = JQuery.MouseMoveEvent;
    import MouseEnterEvent = JQuery.MouseEnterEvent;
    
    interface ICursorPetSettings {
        close: string,
        darkClass: string,
        drag: string,
        hoverClass: string,
        modalClass: string,
        view: string,
        textClass: string,
    }
    
    export default class CursorPet extends Component {
        static initSelector: string = '.cursor-pet';
    
        public mouseX: number;
        public mouseY: number;
        public label: JQuery;
        public targets: string;
    
        settings: ICursorPetSettings;
    
        constructor(element: HTMLElement) {
            super(element);
    
            this.settings = $.extend({
                close: '',
                darkClass: 'is-dark',
                drag: '',
                hoverClass: 'is-hover',
                modalClass: 'is-modal',
                textClass: 'is-text',
                view: '',
            }, this.element.data());
    
            this.mouseMove = this.mouseMove.bind(this);
            this.mouseEnter = this.mouseEnter.bind(this);
            this.mouseLeave = this.mouseLeave.bind(this);
    
            this.label = $('.cursor-pet__label');
            this.targets = '.button, button, a, .textfield, .gallery-slider';
    
            this.init();
        }
    
        init(): void {
            $(window).on('resize', this.resizeHandler.bind(this));
            window.dispatchEvent(new Event('resize'));
    
            window.requestAnimationFrame(this.setPetPosition.bind(this));
            $(window).on('load', this.inputConfirmation.bind(this));
        }
    
        resizeHandler(): void {
            if (!Helpers.isMobileDevice && $(window).width() >= Helpers.bp.md) {
                this.element.removeClass('h-hidden');
                $(window).on('mousemove', this.mouseMove);
                $(this.targets).on('mouseenter', this.mouseEnter);
                $(this.targets).on('mouseleave', this.mouseLeave);
            } else {
                this.element.addClass('h-hidden');
                $(window).off('mousemove', this.mouseMove);
                $(this.targets).off('mouseenter', this.mouseEnter);
                $(this.targets).off('mouseleave', this.mouseLeave);
            }
        }
    
        mouseMove(event: MouseMoveEvent): void {
            this.mouseX = event.clientX;
            this.mouseY = event.clientY;
    
            if (!$(event.target).closest('[data-theme="dark"]').length && !$('body').hasClass('is-header-open')) {
                if ($(event.target).closest('body:not(.is-header-dark) .header').length) {
                    this.element.removeClass(this.settings.darkClass);
                } else {
                    this.element.addClass(this.settings.darkClass);
                }
            } else {
                this.element.removeClass(this.settings.darkClass);
            }
    
            if ($(event.target).closest('.modal-container').length && !$(event.target).closest('.modal').length) {
                this.element.addClass(this.settings.hoverClass);
                this.label.text(this.settings.close);
                this.element.addClass(this.settings.textClass);
                this.element.addClass(this.settings.modalClass);
            } else if ($(event.target).closest('.modal').length) {
                this.element.removeClass(this.settings.hoverClass);
                this.label.text('');
                this.element.removeClass(this.settings.textClass);
                this.element.removeClass(this.settings.modalClass);
            }
        }
    
        mouseEnter(event: MouseEnterEvent): void {
            this.element.addClass(this.settings.hoverClass);
    
            if ($(event.target).closest('.solution').length || $(event.target).closest('.case-study').length) {
                this.label.text(this.settings.view);
                this.element.addClass(this.settings.textClass);
            }
    
            if ($(event.target).closest('.gallery-slider').length) {
                this.label.text(this.settings.drag);
                this.element.addClass(this.settings.textClass);
            }
        }
    
        mouseLeave(): void {
            this.element.removeClass(this.settings.hoverClass);
            this.element.removeClass(this.settings.textClass);
            this.label.text('');
        }
    
        setPetPosition(): void {
            this.element.css('transform', 'translate3d('+ this.mouseX + 'px,' + this.mouseY + 'px, 0)');
    
            window.requestAnimationFrame(this.setPetPosition.bind(this));
        }
    
        inputConfirmation(): void {
            if (whatInput.ask() === 'touch'){
                this.element.addClass('h-hidden');
            } else if (whatInput.ask() === 'keyboard' || whatInput.ask() === 'mouse') {
                this.element.removeClass('h-hidden');
            }
        }
    }
    
  • URL: /components/raw/cursor-pet/cursor-pet.ts
  • Filesystem Path: src/patterns/components/cursor-pet/cursor-pet.ts
  • Size: 4.6 KB
  • Handle: @cursor-pet--default
  • Filesystem Path: src/patterns/components/cursor-pet/cursor-pet.twig
  • Referenced by (1): @preview