How to disable the mouse wheel?

Hello,

I have a page generated by Node-RED for managing my electric heating. I’m increasing the number of zones a bit to better manage my consumption.
On this page, I have a lot of sliders (sliders) and the page is quite large with the hourly schedules.

The problem is that when I scroll down the page with the mouse wheel, if I hover over a slider, it changes its value. If I’m not careful, it can be annoying.

I’ve been trying for a while to disable the mouse wheel events for the sliders without success.

ChatGPT helped me write most of the code.
The events are detected properly, but the mouse wheel remains active on the sliders.

I Use ui-template with this code

<script>
    (function() {
        // Fonction pour désactiver la molette sur un slider
        function disableSliderWheel(slider) {
            slider.addEventListener('wheel', (event) => {
console.log(`Desactivation molette slider ${slider}`);
                event.stopImmediatePropagation(); // Empêche tout autre écouteur d'exécuter cet événement
                event.preventDefault(); // Annule le comportement par défaut
            }, { passive: false }); // Permet de prévenir explicitement l'événement
        }

        // Observer les changements dans le DOM
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList') {
console.log(`Mutation détectée`);
                    // Rechercher tous les sliders ajoutés dynamiquement
                    const sliders = document.querySelectorAll('md-slider');
                    sliders.forEach((slider) => {
                        if (!slider.dataset.wheelDisabled) {
                            disableSliderWheel(slider);
                            slider.dataset.wheelDisabled = true; // Marquer comme traité
                        }
                    });
                }
            });
        });

        // Configurer l'observation pour tout le document
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        // Désactiver la molette pour les sliders déjà présents au chargement
        document.addEventListener("DOMContentLoaded", () => {
            const sliders = document.querySelectorAll('md-slider');
            sliders.forEach((slider) => {
console.log(`Desactivation molette slider déjà présent ${slider}`);
                disableSliderWheel(slider);
                slider.dataset.wheelDisabled = true;
            });
        });
    })();
</script>

Slider elements are likely to be compound elements with a shadow dom. As such, it may be that you aren't trapping the mouse wheel on the right element. You will need to use your browser dev tools to identify the exact element possible.

Alternatively, add a wheel event on document but just print out the event.target.tagName or id to see what element is actually triggered.

Thank you for your response. I don’t know what a shadow DOM is. I will look into it.

The slider element is:

<md-slider ng-if="me.item.outs==='all'" flex="100" min="1" max="5" step="1" 
  ng-model="me.item.value" 
  aria-label="Mode Général" 
  ng-change="me.valueChanged(10)" 
  ng-on-wheel="me.wheel($event)" 
  style="z-index: 1; touch-action: none; min-width: 32px;" 
  ng-attr-md-vertical="{{ (me.item.width < me.item.height) || undefined}}" 
  ng-attr-md-invert="{{ me.item.invert || undefined}}" 
  class="ng-pristine ng-untouched ng-valid flex-100 ng-not-empty" 
  aria-invalid="false">
    <div class="md-slider-wrapper" tabindex="0" role="slider" style="touch-action: pan-y;" aria-valuemin="1" aria-valuemax="5" aria-valuenow="3">
      <div class="md-slider-content">
        <div class="md-track-container"><div class="md-track"></div>
        <div class="md-track md-track-fill" style="width: 50%;"></div>
        <div class="md-track-ticks"></div></div>
        <div class="md-thumb-container" style="left: 50%;">
        <div class="md-thumb"></div>
        <div class="md-focus-thumb"></div>
        <div class="md-focus-ring"></div>
        <div class="md-sign">
          <span class="md-thumb-text">3</span>
        </div>
         <div class="md-disabled-thumb"></div>
        </div>
      </div>
    </div>
</md-slider>

There is the me.wheel($event) function in the ng-on-wheel parameter. It seems that one of the two should be modified.

Blockquote
Alternatively, add a wheel event on document but just print out the event.target.tagName or id to see what element is actually triggered.

give nothing : undefined