Skip to content

Instantly share code, notes, and snippets.

@IgorGavrilenko
IgorGavrilenko / прилипающий блок
Last active January 19, 2024 09:36
прилипающий блок
gsap.registerPlugin(ScrollTrigger, ScrollSmoother, ScrollToPlugin);
// Sticky menu
function stickyMenuFunc() {
const sidebarElement = document.querySelector('.list-anchor');
const sectionSidebar = '.section__sidebar';
if (sidebarElement) {
gsap.to(sidebarElement, {
scrollTrigger: {
trigger: sidebarElement,
@IgorGavrilenko
IgorGavrilenko / нумерация
Created June 27, 2022 14:31
нумерация
(function (){
const $infoListCount = $('.info__list');
const $infoItemCount = '.info__item';
const $infoNumCount = '.info__num';
$infoListCount.each(function(){
$($infoItemCount, this).each(function(i){
$(this).find($infoNumCount).text(('0' + (i+1)).slice(-2));
});
});
})();
@IgorGavrilenko
IgorGavrilenko / липкая шапка
Created June 3, 2022 16:55
липкая шапка
//fixed header
$(function() {
const header = $('.header');
const headerFixed = 'header--fixed';
$(window).scroll(function() {
if($(this).scrollTop() > 1) {
header.addClass(headerFixed);
} else {
header.removeClass(headerFixed);
}
@IgorGavrilenko
IgorGavrilenko / прижатый подвал
Created January 13, 2022 15:02
прижатый подвал
html{
height: 100%;
}
body{
display: flex;
flex-direction: column;
height: 100%;
}
.header{
flex: 0 0 auto;
@IgorGavrilenko
IgorGavrilenko / группа чекбоксов
Created October 5, 2021 10:59
группа чекбоксов
<div class="">
<label class="form-label">
<input class="jq-check-all" type="checkbox" data-id="sort">
<span class="form-label__capt">Все</span>
</label>
<label class="form-label">
<input class="jq-check-rest" type="checkbox" data-id="sort">
<span class="form-label__capt"></span>
</label>
</div>
@IgorGavrilenko
IgorGavrilenko / dns-prefetch
Created September 3, 2021 13:07
dns-prefetch
<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="https://www.googletagmanager.com">
<link rel="dns-prefetch" href="https://connect.facebook.net">
<link rel="dns-prefetch" href="https://www.google-analytics.com">
<link rel="dns-prefetch" href="https://adservice.google.com">
<link rel="dns-prefetch" href="https://staticxx.facebook.com">
<link rel="dns-prefetch" href="https://www.facebook.com">
<link rel="dns-prefetch" href="https://tpc.googlesyndication.com">
<link rel="dns-prefetch" href="https://ajax.googleapis.com">
<link rel="dns-prefetch" href="https://fonts.googleapis.com">
@IgorGavrilenko
IgorGavrilenko / jq активный пункт меню
Created August 27, 2021 12:27
jq активный пункт меню
var link = $('.link');
link.each(function() {
if ( (window.location.pathname.indexOf( $(this).attr('href') ) ) > -1) {
$(this).addClass('selected');
}
});
@IgorGavrilenko
IgorGavrilenko / js collapse
Last active March 28, 2023 11:14
js collapse
document.querySelectorAll('.js-collapse').forEach(function(accordion) {
accordion.addEventListener('click', function(event) {
//event.preventDefault();
let subAccordion = accordion.querySelector('.js-collapse-target');
let clickTarget = event.target;
if( clickTarget.closest('.js-collapse-toggle') ) {
accordion.classList.toggle('open');
setTimeout(function() {
if (subAccordion.style.maxHeight) {
subAccordion.style.maxHeight = null;
function hasClass(el, className) {
return el.classList ? el.classList.contains(className) : new RegExp('\\b'+ className+'\\b').test(el.className);
}
function addClass(el, className) {
if (el.classList) el.classList.add(className);
else if (!hasClass(el, className)) el.className += ' ' + className;
}
function removeClass(el, className) {
if (el.classList) el.classList.remove(className);
else el.className = el.className.replace(new RegExp('\\b'+ className+'\\b', 'g'), '');
@IgorGavrilenko
IgorGavrilenko / js обертка элементов
Last active August 26, 2021 15:13
обертка элементов
// ready (MutationObserver)
(function(win) {
'use strict';
var listeners = [],
doc = win.document,
MutationObserver = win.MutationObserver || win.WebKitMutationObserver,
observer;
function ready(selector, fn) {
listeners.push({
selector: selector,