Skip to content

Instantly share code, notes, and snippets.

View b-aleksei's full-sized avatar

Алексей b-aleksei

View GitHub Profile
@b-aleksei
b-aleksei / navigate-menu.html
Last active March 1, 2021 17:11
navigate menu
<nav class="header__nav nav">
<button class="nav__toggle" type="button" aria-label="Отобразить меню"
aria-controls="main-menu" aria-expanded="false">
<span class="nav__burger"></span>
</button>
<ul id="main-menu" class="nav__list">
<li class="nav__item">
<a class="nav__link" href="#">О нас</a>
</li>
</ul>
@b-aleksei
b-aleksei / button.js
Last active August 15, 2020 13:30
button wave
"use strict";
const addElement = function (e) {
const button = e.currentTarget;
const el = e.currentTarget.lastElementChild;
const mValue = Math.max(button.clientWidth, button.clientHeight);
el.style.width = el.style.height = mValue + 'px';
el.classList.remove('pulse');
setTimeout(() => {
@b-aleksei
b-aleksei / phoneMask.js
Last active November 17, 2020 13:24
PhoneMask
const COUNTRY_CODE = 7;
const onInputPhoneInput = ({target}) => {
const matrix = `+${COUNTRY_CODE} (___) ___-__-__`;
let counter = 0;
let val = target.value.replace(/\D/g, '');
if (!val.length) {
val = `${COUNTRY_CODE}`;
}
const ua = window.navigator.userAgent.toLowerCase();
const isIe = (/trident/gi).test(ua) || (/msie/gi).test(ua);
const goToTarget = function (target) { // фолбэк для ie11
const y = target.offsetTop;
const moveTo = function () {
if (window.pageYOffset < y) {
window.scrollBy(0, 60);
setTimeout(moveTo);
@b-aleksei
b-aleksei / multi-modal.js
Last active December 7, 2021 11:18
multi-modal
const focusableEls = `a[href]:not(:disabled), input:not(:disabled):not([type="hidden"]),
select:not(:disabled), textarea:not(:disabled), button:not(:disabled), [contenteditable],
[tabindex]:not([tabindex="-1"])`;
const isTouchSupported = () => ('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch);
const getHtmlElement = (selector, ctx = document) => {
const node = typeof selector === 'string' ? ctx.querySelector(selector) : selector;
if (node instanceof HTMLElement) {
return node;
}
@b-aleksei
b-aleksei / debounce.js
Created October 21, 2020 16:15
function debounce(func, ms) { let timeout; return () => { clearTimeout(timeout); timeout = setTimeout(() => { func(); }, ms); }; debounce
function debounce(func, ms) {
let timeout;
return () => {
clearTimeout(timeout);
timeout = setTimeout(() => {
func();
}, ms);
};
}
@b-aleksei
b-aleksei / DateInputMask.js
Last active March 1, 2021 11:17
DateInputMask
input.addEventListener('keypress', function(e) {
if(/\D/.test(e.key)) {
e.preventDefault();
}
const len = input.value.length;
if(len === 1 || len === 4) {
setTimeout(() => {
input.value += '/';
})
@b-aleksei
b-aleksei / smoothScroll.js
Last active September 16, 2021 15:24
smoothScroll
const easingOutQuint = (x, t, b, c, d) => c * ((t = t / d - 1) * t * t * t * t + 1) + b;
const makeScroll = (node, value, key = 'scrollTop') => {
let startTime = null;
const offset = node[key];
const gap = value - offset;
const duration = 1000;
const step = (t) => {
if (!startTime) {
@b-aleksei
b-aleksei / asideNav.js
Created November 22, 2020 12:20
asideNav
const emptyEl = document.createElement('div');
let isObserverSupport = false;
const easingOutQuint = (x, t, b, c, d) => c * ((t = t / d - 1) * t * t * t * t + 1) + b;
const smoothScrollFallback = (node, key, target) => {
const offset = node[key];
const gap = target - offset;
const duration = 1000;
let startTime = null;
const step = (t) => {
@b-aleksei
b-aleksei / double-range_dbrange.js
Last active January 10, 2021 18:30
WC-double-range
import Template from './template.js';
export default class Dbrange extends HTMLElement {
constructor() {
super();
this.root = this.attachShadow({mode: 'open'});
this.root.innerHTML = Template.render();
this.dom = Template.mapDOM(this.root);
this.eventNames = {
pointerdown: 'pointerdown',