How to Create a Custom Switcher for JetSmartFilters Radio Filter
Description
Switcher for JetSmartFilters
Learn how to transform a standard JetSmartFilters radio filter into a stylish and functional switcher! This step-by-step guide covers:
- Adding custom CSS to style the switcher.
- Implementing JavaScript for dynamic behavior.
- Applying changes specifically to selected filters using a unique class.
Perfect for those who want to enhance their website’s interactivity and design while using JetSmartFilters. Watch now and create your own custom switcher in minutes!
???? Resources:
JetSmartFilters plugin: Link
???? Don’t forget to like, comment, and subscribe for more tutorials!
<style>
.switcher-filter-style .jet-radio-list__input {
opacity: 0;
position: absolute;
width: 0;
height: 0;
}
.switcher-filter-style .jet-radio-list__label {
display: none; /* Ocultar completamente el label */
}
.switcher-filter-style .jet-radio-list__button {
width: 60px;
height: 30px;
background-color: #ccc;
border-radius: 15px;
border: 2px solid #ccc; /* Borde para parecer un switcher */
position: relative;
transition: background-color 0.3s ease-in-out, border-color 0.3s ease-in-out;
cursor: pointer;
}
.switcher-filter-style .jet-radio-list__decorator {
display: none; /* Ocultar completamente el decorador */
}
.switcher-filter-style .jet-radio-list__button::after {
content: "OFF";
width: 26px;
height: 26px;
background-color: white;
border-radius: 50%;
position: absolute;
top: 2px;
left: 2px;
color: #000; /* Color inicial del texto */
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
font-weight: bold;
transition: transform 0.3s ease-in-out, background-color 0.3s ease-in-out;
}
.switcher-filter-style .jet-radio-list__input:checked ~ .jet-radio-list__button {
background-color: #4caf50;
border-color: #4caf50;
}
.switcher-filter-style .jet-radio-list__input:checked ~ .jet-radio-list__button::after {
transform: translateX(30px);
background-color: green; /* Cambia el color cuando está en ON */
color: #fff; /* Cambia el color del texto */
content: "ON"; /* Cambia el texto a ON */
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const switcherFilters = document.querySelectorAll('.switcher-filter-style .jet-radio-list__item');
switcherFilters.forEach(item => {
const input = item.querySelector('.jet-radio-list__input');
const button = item.querySelector('.jet-radio-list__button');
item.addEventListener('click', () => {
const isChecked = input.checked;
if (isChecked) {
input.checked = false;
input.value = 'false';
} else {
input.checked = true;
input.value = 'true';
}
// Dispatch a change event to trigger any listeners
input.dispatchEvent(new Event('change'));
});
});
});
</script>
How to Create a Custom Switcher for JetSmartFilters Radio Filter
Dec 28, 2024
Participants
Play Video
Tags : JetSmartFilters
What you think about How to Create a Custom Switcher for JetSmartFilters Radio Filter ?
{{ reviewsTotal }}{{ options.labels.singularReviewCountLabel }}
{{ reviewsTotal }}{{ options.labels.pluralReviewCountLabel }}
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}