Skip to content

Instantly share code, notes, and snippets.

View b-aleksei's full-sized avatar

Алексей b-aleksei

View GitHub Profile
progressBar = document.querySelector('progress');
output = document.querySelector('output');
xhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable) {
var v = (e.loaded / e.total) * 100;
progressBar.value = v;
output.value = Math.round(v) + '%';
progressBar.textContent = progressBar.value.toString(); // Если браузер не поддерживает элемент progress
}
::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-top: none;
border-bottom: 15px solid red;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
@b-aleksei
b-aleksei / scroll-to-top.js
Last active June 8, 2020 08:36
scroll-to-top
function trackScroll() {
let scrolled = window.pageYOffset;
let coords = document.documentElement.clientHeight;
if (scrolled > coords) {
goToTop.classList.add("to_top-show");
}
if (scrolled < coords) {
goToTop.classList.remove("to_top-show");
}
}
// for IE11
const supportsTemplate = 'content' in document.createElement('template');
// the function takes a template and returns a DOM element
const createElement = supportsTemplate
? function (html) {
const template = document.createElement('template');
template.innerHTML = html;
return template.content.firstElementChild;
}
// <div id="calendar"></div>
function createCalendar(elem, year, month) {
let mon = month - 1; // месяцы в JS идут от 0 до 11, а не от 1 до 12
let d = new Date(year, mon);
let table = '<table><tr><th>пн</th><th>вт</th><th>ср</th><th>чт</th><th>пт</th><th>сб</th><th>вс</th></tr><tr>';
// пробелы для первого ряда
@b-aleksei
b-aleksei / requestAnimationFrame.js
Last active June 19, 2020 13:07
requestAnimationFrame
// <progress id="elem" style="width: 5%;" onclick="anim.start()"></progress>
class Animation {
constructor({draw, duration}) {
this.draw = draw;
this.duration = duration;
}
animate(time) {
@b-aleksei
b-aleksei / modal.js
Last active August 7, 2020 16:10
modal
/*
Класс для предотвращения скрола
.body-lock {
overflow-y: scroll;
position:fixed;
}
*/
const openClosePopup = function (obj) {
@b-aleksei
b-aleksei / phone-validation-regExp.js
Last active August 12, 2020 13:03
phone-validation-regExp
/* html
<div class="form__input-wrap">
<input name="name" data-validate="true" type="text" pattern="[A-z,А-я]{2,}" placeholder="Введите Ваше Имя"
aria-label="Введите Ваше Имя" required>
<span class="form__error form__error--name">Имя должно содержать минимум 2 буквы</span>
</div>
<div class="form__input-wrap">
<input name="phone" data-validate="true" type="text" pattern="\+7\s\([0-9]{3}\)\s[0-9]{3}\s[0-9]{2}\s[0-9]{2}"
placeholder="Введите Ваш номер телефона"
aria-label="Введите Ваш номер телефона" required>
@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 / smoothScrollForIE.js
Last active August 21, 2020 09:08
smooth-scroll
const ua = window.navigator.userAgent.toLowerCase();
const isIe = (/trident/gi).test(ua) || (/msie/gi).test(ua);
if (isIe) {
const makeSmoothScroll = function (link) {
link.addEventListener('click', function (e) {
e.preventDefault();