Skip to content

Instantly share code, notes, and snippets.

View b-aleksei's full-sized avatar

Алексей b-aleksei

View GitHub Profile
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 / 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 / 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}`;
}
@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 / range.js
Last active December 15, 2020 06:39
range
const range = document.querySelector('.range');
const thumb = document.querySelector('.range__thumb');
let isTouch = false;
let touch = 'pointerdown';
let touchMove = 'pointermove';
let touchUp = 'pointerup';
if ('ontouchstart' in window) {
isTouch = true;
touch = 'touchstart';
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Slider Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<wc-slider min="50" max="200" step="0" value="100"></wc-slider>
@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',
@b-aleksei
b-aleksei / input-password.js
Created February 18, 2021 08:40
input-password
export const showPassword = (btn) => {
const input = btn.parentElement.querySelector('input');
if (btn.classList.contains('show')) {
btn.classList.remove('show');
input.type = 'password';
} else {
btn.classList.add('show');
input.type = 'text';
@b-aleksei
b-aleksei / rating.html
Last active February 18, 2021 18:27
star-rating
<fieldset class="rating">
<legend class="visually-hidden">Звездный рейтинг</legend>
<input id="film-1" type="radio" name="film" value="1">
<input id="film-2" type="radio" name="film" value="2">
<input id="film-3" type="radio" name="film" value="3">
<input id="film-4" type="radio" name="film" value="4" checked>
<input id="film-5" type="radio" name="film" value="5">
<label for="film-5" aria-label="5 звезд">
<svg width="44" height="43">
@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 += '/';
})