Attempting to fix checkbox styling

main
riley 10 months ago
parent c482186802
commit 00ea79a06b

@ -3028,6 +3028,7 @@ strong {
} }
} }
/* The switch - the box around the slider */
.switch { .switch {
position: relative; position: relative;
display: inline-block; display: inline-block;
@ -3035,12 +3036,14 @@ strong {
height: 34px; height: 34px;
} }
/* Hide default HTML checkbox */
.switch input { .switch input {
opacity: 0; opacity: 0;
width: 0; width: 0;
height: 0; height: 0;
} }
/* The slider */
.slider { .slider {
position: absolute; position: absolute;
cursor: pointer; cursor: pointer;
@ -3049,7 +3052,6 @@ strong {
right: 0; right: 0;
bottom: 0; bottom: 0;
background-color: #ccc; background-color: #ccc;
-webkit-transition: .4s;
transition: .4s; transition: .4s;
} }
@ -3061,7 +3063,6 @@ strong {
left: 4px; left: 4px;
bottom: 4px; bottom: 4px;
background-color: white; background-color: white;
-webkit-transition: .4s;
transition: .4s; transition: .4s;
} }
@ -3074,17 +3075,5 @@ input:focus + .slider {
} }
input:checked + .slider:before { input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px); transform: translateX(26px);
} }
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}

@ -62,17 +62,45 @@
</div> </div>
<script> <script>
{ {
const nav = document.querySelector(".navbar"); // Function to run when the DOM is fully loaded
let lastScrollY = window.scrollY; document.addEventListener("DOMContentLoaded", function() {
// Find all checkboxes
window.addEventListener("scroll", () => { var checkboxes = document.querySelectorAll('input[type="checkbox"]');
if (lastScrollY < window.scrollY) {
nav.classList.add("navbar--hidden"); // Loop over each checkbox
} else { checkboxes.forEach(function(checkbox) {
nav.classList.remove("navbar--hidden"); // Create the switch
} var switchElement = document.createElement('label');
switchElement.className = 'switch';
// Create the input for the switch
var input = document.createElement('input');
input.type = 'checkbox';
input.checked = checkbox.checked;
switchElement.appendChild(input);
// Create the slider for the switch
var slider = document.createElement('span');
slider.className = 'slider';
switchElement.appendChild(slider);
// Add the switch to the page
checkbox.parentNode.insertBefore(switchElement, checkbox.nextSibling);
lastScrollY = window.scrollY; // Hide the original checkbox
checkbox.style.display = 'none';
// When the switch is clicked, update the checkbox
input.addEventListener('change', function() {
checkbox.checked = this.checked;
});
// When the checkbox is updated (e.g. by JavaScript), update the switch
var observer = new MutationObserver(function() {
input.checked = checkbox.checked;
});
observer.observe(checkbox, { attributes: true });
});
}); });
} }
</script> </script>

Loading…
Cancel
Save