1

We want to write code for an mousewheel-event on an div-container. Using the following code works fine in Browsers Edge and Chrome:

<div id="scroll-container" @onmousewheel="MouseWheelEventHandler">
    [...]
</div>

@code 
{
    private async Task MouseWheelEventHandler()
    {
        System.Console.WriteLine("Scroll"); // works in Chrome and Edge, but not in FF
    }
}

But the MouseWheelEventHandler is not firing in Firefox.

Regarding this Post with JavaScript we had to bind the mousewheel by DOMMouseScroll. (DOMMouseScroll is deprecated and wheel would do the job in future). This post is a solution for JavaScript, but not blazor.

document.getElementById("scroll-container").addEventListener("DOMMouseScroll", function(){...}, false);

How can I bind the mouse-scroll event for FF in Blazor Web Assembly?

Simon
  • 4,157
  • 2
  • 46
  • 87
  • 1
    See [this](https://stackoverflow.com/questions/16788995/mousewheel-event-is-not-triggering-in-firefox-browser) SO question. It's the same reason. – Eldar Dec 04 '20 at 07:54
  • I'd recommend [this answer](https://stackoverflow.com/a/28848965/7095512) in the same SO question Eldar posted. – Artur Dec 04 '20 at 07:57
  • @Eldar: Please read my question. My problem is not JavaScript which solution is already known to me. My querstion targets an solution for blazor. – Simon Dec 04 '20 at 08:08
  • Does this answer your question? [mousewheel event is not triggering in firefox browser](https://stackoverflow.com/questions/16788995/mousewheel-event-is-not-triggering-in-firefox-browser) – Quango Dec 04 '20 at 08:51
  • @Quango: As you can see in my question, I already have mentioned your posted link. – Simon Dec 04 '20 at 08:55

1 Answers1

4

For firefox you have to add the event onwheel:

<div id="scroll-container" @onmousewheel="MouseWheelEventHandler" @onwheel="MouseWheelEventHandler">
    [...]
</div>

@code 
{
    private async Task MouseWheelEventHandler()
    {
        System.Console.WriteLine("Scroll");
    }
}

Fiddle

Eldar
  • 9,781
  • 2
  • 10
  • 35
Joachim Marder
  • 782
  • 5
  • 12