Skip to content

Instantly share code, notes, and snippets.

(function() {
if (!Element.prototype.matches) {
// определяем свойство
Element.prototype.matches = Element.prototype.matchesSelector ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector;
<style>
.object-fit img {
object-fit: cover;
width: 30%;
height: 100px;
}
// отложенная загрузка скриптов
<script>
window.addEventListener('load', function() {
let element = document.createElement('script');
element.src = 'script.js';
document.body.appendChild(element);
});
</script>
// Array.prototype.findIndex
if (!Array.prototype.findIndex) {
Array.prototype.findIndex = function(predicate) {
if (this == null) {
throw new TypeError('Array.prototype.findIndex called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
//https://www.html5rocks.com/ru/tutorials/workers/basics/
var worker = new Worker('doWork.js');
worker.addEventListener('message', function(e) {
console.log('Worker said: ', e.data);
}, false);
worker.postMessage('Hello World');
function applyForVisa(document) {
console.log("Обработка заявления...");
return new Promise( (resolve, reject) => {
setTimeout(() => {
Math.random() > 0.5? resolve({value: "visa"}) : reject("В визу отказано");
}, 1000);
} )
}
function getVisa(visa) {
http://milkywaydoor.ru/znania/web-stat/biblioteka-animate-css-primer/
// install Babel
npm install --save-dev gulp-babel@7 babel-core babel-preset-env
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
// код для мобильных устройств
} else {
// код для обычных устройств
}
// Проверить есть ли поддержка touch евентов
function is_touch_device() {
function setSelectionRange(input, selectionStart, selectionEnd) { // функция для постановки курсора
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);