let $grid = $('.card__list').isotope({
itemSelector: '.card--small',
transitionDuration: 0,
});
let showMoreBtn = document.querySelector('.js-load-more-btn');
let maxCardsToShow = 6;
let cardsToShow = 6;
let filteredItems = [];
function updateCardsDisplay() {
filteredItems.forEach((item, index) => {
if (index < maxCardsToShow) {
item.element.style.display = 'flex';
} else {
item.element.style.display = 'none';
}
});
}
$grid.isotope('on', 'arrangeComplete', function(items) {
filteredItems = items;
maxCardsToShow = 6;
updateCardsDisplay();
showMoreBtn.style.display = (filteredItems.length > maxCardsToShow) ? 'block' : 'none';
});
showMoreBtn.addEventListener('click', () => {
let cardLength = filteredItems.length;
for (let i = maxCardsToShow; i < Math.min(maxCardsToShow + cardsToShow, cardLength); i++) {
filteredItems[i].element.style.display = 'flex';
}
maxCardsToShow += cardsToShow;
if (maxCardsToShow >= cardLength) {
showMoreBtn.style.display = 'none';
}
});
{///
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
}
///
}
// layout.pug
html
head
block title
title Layout Default Title
body
block content
// index.pug
extends layout.pug
block title
title Index page
block content
p Lorem ipsum dolor sit amet.
document.querySelector('form')?.addEventListener('submit', (event) => {
const form = new FormData(event.currentTarget);
let isValid = true;
if (form.get('name').length <= 2) {
isValid = false;
}
if (!isValid) {
// Отмена отправки формы
event.preventDefault();
}
alert(`Is Valid: ${isValid}`);
});
function getPosts(callback) {
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://jsonplaceholder.typicode.com/posts");
xhr.addEventListener("load", () => {
const response = JSON.parse(xhr.responseText);
console.log(response);
callback(response);
})
xhr.addEventListener("error", () => {
console.log("error!");
})
xhr.send();
}