function fadePreLoader(el) {
if (isVisiblePreloader) {
el.style.opacity = 1;
var interPreLoader = setInterval(function () {
el.style.opacity = el.style.opacity - 0.05;
if (el.style.opacity <= 0.05) {
clearInterval(interPreLoader);
preLoader.style.display = "none";
}
}, 16);
isVisiblePeloader = false;
}
}
<div id="before-load"></div>
<script>
var preLoader = document.getElementById("before-load");
isVsiblePreloader = true;
setTimeout(function () {
fadePreLoader(preLoader);
}, 10000);
</script>
window.onload = function () {
fadePreLoader(preLoader);
};
isVisiblePeloader = false;
, что предотвратит скрытие прелоадера второй раз. function prettify (num) {
var n = num.toString();
var separator = " ";
return n.replace(/(\d{1,3}(?=(?:\d\d\d)+(?!\d)))/g, "$1" + separator);
}
var $test = $(".test");
var val = $test.prop("value");
$test.prop("value", prettify(val));
const itemSelector = '.menu-catalog__item';
const buttonSelector = '.menu-catalog__link';
const className = 'menu-catalog__open';
const $items = $(itemSelector).on('click', buttonSelector, e => {
$items.not(e.delegateTarget).removeClass(className);
$(e.delegateTarget).toggleClass(className);
});
// или
const items = document.querySelectorAll(itemSelector);
const onClick = ({ target: t }) =>
t.closest(buttonSelector) && items.forEach(n => {
n.classList[n.contains(t) ? 'toggle' : 'remove'](className);
});
items.forEach(n => n.addEventListener('click', onClick));
$(function() {
let length = Array.reduce($('.lang-item a'), (result, item) => {
return Math.max(result, $(item).width())
}, 0);
console.log(length);
});
var $item = $('a', $('.lang-item'));
var maxWidth = Math.max.apply(null, $.makeArray($item).map(function(item) {
return item.offsetWidth;
}));
console.log(maxWidth);
const $item = $('a', $('.lang-item'));
const maxWidth = Math.max(...Array.from($item).map((item) => item.offsetWidth));
console.log(maxWidth);
$elems.change(function() {
...
}).change();
function onChange() {
...
}
$elems.change(onChange).each(onChange);