Skip to content

Question - How to handle window or body onscroll in Blazor server side? #18072

@fingers10

Description

@fingers10

I'm developing my first blazor server side application. I need to capture onscroll event of window or body in my blazor server side application. Right now I implemented this using a script file where I capture the event and do my logics in there as shown below.

For window:

window.onscroll = function() {myFunction()};

function myFunction() {
  //  ... my logics here
}

How to capture onscroll event of body tag? In blazor server side body is in _Host.cshtml file where I cannot use @onscroll since it is not a component

For body:

<body onscroll="myFunction()">

The above one works but I'm not happy with this implementation while using blazor.

Please assist on how to implement this purely with C# or it is acceptable to use Javascript for this. I'm confused.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions