Skip to content

Instantly share code, notes, and snippets.

View basilalex's full-sized avatar

Oleksandr Bazylevskyi basilalex

View GitHub Profile
@basilalex
basilalex / main.js
Created March 23, 2017 14:33
Ставит запятые в числах
// Ставит запятые в числах
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
@basilalex
basilalex / main.js
Created March 29, 2017 14:25
RegExp for email check.
function checkEmail(email) {
const reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
(!reg.test(email)) ? return false : return true;
}
@basilalex
basilalex / index.html
Created April 26, 2017 09:57
Responsive images with high dpi and screen size.
<picture>
<source
media="(min-width: 1024px)"
srcset="opera-fullshot-1x.jpg 1x,
opera-fullshot-2x.jpg 2x,
opera-fullshot-3x.jpg 3x">
<img
src="opera-closeup-1x.jpg" alt="The Oslo Opera House"
srcset="opera-closeup-2x.jpg 2x,
opera-closeup-3x.jpg 3x">
@basilalex
basilalex / index.html
Created July 11, 2017 14:16
Паттерн форматирования номера телефона для Украины.
<input
type="tel"
name="phone"
placeholder="Телефон"
pattern="[\+]\d{2}\s[\(]\d{3}[\)]\s\d{3}[\-]\d{2}[\-]\d{2}"
minlength="13"
maxlength="13"
/>
@basilalex
basilalex / index.js
Created July 16, 2017 07:25
scrollDirection
let lastScrollTop = 0;
function scrollDirection() {
const st = window.pageYOffset || document.documentElement.scrollTop;
if (st > lastScrollTop) {
// downscroll code
} else {
// upscroll code
}
@basilalex
basilalex / img.js
Last active October 26, 2017 02:37
Preload array of images with Promise
export default arr => new Promise((resolve) => {
const imgs = [];
arr.forEach((path) => {
const img = new Image();
img.onload = () => {
imgs.push(img);
if (imgs.length === arr.length) resolve(imgs);
};
img.src = `../img/phone/phone_000${path}`;
});