Last active
December 13, 2022 10:51
-
-
Save IgorGavrilenko/910a22d9e5aeb096449876f1c0efea16 to your computer and use it in GitHub Desktop.
spoiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
function tab(trigger, item) { | |
// $(item).hide() | |
$(trigger).click(function(event) { | |
event.stopPropagation(); | |
$(item).not($(this).next()).slideUp(250); | |
$(this).next().slideToggle(250); | |
return false; | |
}) | |
$('html').click(function(event) { | |
if ($(event.target).closest(item).size()) return; | |
$(item).slideUp(250); | |
}); | |
} | |
var trigger = '.tab-mob-trigger'; | |
var item = '.tab-mob-item'; | |
tab(trigger, item); | |
// spoiler | |
(function() { | |
document.querySelector('.spoiler').addEventListener('click', spoilerClickHandler); | |
function spoilerClickHandler(evt) { | |
const spoilerSwitchElem = evt.target.closest('.spoiler__head') | |
if (spoilerSwitchElem) { // если клик по dt | |
spoilerSwitchElem.closest('.spoiler__item') | |
.classList.toggle('active') // обертке переключаем active | |
} | |
} | |
})(); | |
})(); | |
(function (){ | |
var $item = $('.tab-mob-trigger'), | |
$ItemActiveClass = 'tab-active'; | |
$item.each(function(a){ | |
$(this).on('click', function() { | |
$item | |
.removeClass($ItemActiveClass) | |
.eq(a) | |
.addClass($ItemActiveClass); | |
}); | |
}); | |
$('html').click(function(event) { | |
if ($(event.target).closest($item).size()) return; | |
$item.removeClass($ItemActiveClass); | |
}); | |
}()); | |
(function (){ | |
var $parent = $('.home-price'); | |
var $item = $('.home-price__btn'); | |
var $ItemActiveClass = 'is-active'; | |
$item.on('click', function() { | |
if(!$(this).hasClass($ItemActiveClass)) { | |
$(this).addClass($ItemActiveClass); | |
} else { | |
$(this).removeClass($ItemActiveClass); | |
} | |
}); | |
$('html').on('click', function(event) { | |
if ($(event.target).closest($parent).size()) return; | |
$item.removeClass($ItemActiveClass); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment