简体   繁体   English

C# Blazor 5.0 onscroll 事件未触发

[英]C# Blazor 5.0 onscroll event not firing

I'm trying to use @onScroll event but it's not firing at all... I prefer not to use Javascript if it's possible.我正在尝试使用@onScroll事件,但它根本没有触发......如果可能的话,我宁愿不使用 Javascript。

<div @onscroll="OnScrollChangeValue" class="sub-header p-10 d-none d-lg-block">
    <div class="container">
        <div class="row header-wrapper">
            <div class="col-lg-6">
            </div>
            <div class="col-lg-6 text-left">
                <div id="cl_switcher_wrapper">
                </div>
                <div class="dropdown dropdown-store-header dropdown-store-header-left hidden-xs">
                    <a class="circle-action dropdown-toggle" data-login-link="" href="https://nory.sa/login" rel="nofollow">
                        <span class="theme-icon-user"></span>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

private async Task  OnScrollChangeValue(EventArgs e)
{
    OnScrollValue = "gg";
}

I understood after MrC aka Shaun Curtis answer that the event must be in the same dev that contains most of the page..but in my case still not working在 MrC aka Shaun Curtis 回答之后,我明白该事件必须在包含大部分页面的同一个开发中......但在我的情况下仍然无法正常工作

Updated code更新代码

<div @onscroll="OnScrollChangeValue" class="store-home salla-theme_6 color-mode-light font-dinnextltarabic-regular">
    <Header></Header>
    <h1>@OnScrollValue</h1>
    @Body

@code{ @代码{

public int OnScrollValue { get; set; }
private void OnScrollChangeValue(EventArgs e)
{
    OnScrollValue++;
}

} }

Updated 1.0更新 1.0

I deleted 99% of the app and the event not firing here the code我删除了应用程序的 99% 并且事件没有在这里触发代码

<div   @onscroll="OnScrollChangeValue" >


  
    <h1>@OnScrollValue</h1>
    @Body
i closed the div but it not showing here idk 我关闭了 div 但它没有在这里显示 idk

@code{ @代码{

 public int OnScrollValue { get; set; } private void OnScrollChangeValue(EventArgs e) { OnScrollValue++; }

} }

at the @body only text with one div在@body 中只有一个 div 的文本

Update 2.0更新 2.0

it appears the event firing only inside child div inside the main page..what i mean the main scrollbar for that main page will not fire the event..but if you tried to put div with style overflow:scroll then the event will fire only inside the div which have overflow:scroll...if you tried to put overflow scroll in main div it won't work看来事件只在主页内的子 div 内触发..我的意思是该主页的主滚动条不会触发事件..但是如果你试图将 div 与样式溢出:滚动然后事件只会触发在有溢出的 div 中:滚动...如果您尝试将溢出滚动放在主 div 中,它将不起作用

style="height:1000px;overflow:scroll" it work with this line of code but i have two scrollbar one on the left and the other on the right style="height:1000px;overflow:scroll" 它适用于这行代码,但我有两个滚动条,一个在左边,另一个在右边

You don't need to revert to JS, this simple demo shows the scrolling event working.你不需要恢复到 JS,这个简单的演示展示了滚动事件的工作。 You need to look at what your CSS classes are up to.你需要看看你的 CSS 类是做什么的。

@page "/Scroll"
<h3>Scrolling</h3>

<div class="scroll" @onscroll="OnScroll">
    It is a good platform to learn programming.
    It is an educational website. Prepare for the Recruitment drive
    of product based companies like Microsoft, Amazon, Adobe etc with
    a free online placement preparation course. The course focuses
    on various MCQ's & Coding question likely to be asked in the
    interviews & make your upcoming placement season efficient and
    successful. Also, any geeks can help other geeks by writing
    articles on the GeeksforGeeks, publishing articles follow few
    steps that are Articles that need little modification/improvement
    from reviewers are published first. To quickly get your articles
    reviewed, please refer existing articles, their formatting style,
    coding style, and try to make you are close to them. In case you
    are a beginner, you may refer Guidelines to write an Article
</div>
<div class="m-2 p-2">Scroll events: @counter</div>


<style>

    div.scroll {
        margin: 4px, 4px;
        padding: 4px;
        width: 500px;
        height: 110px;
        overflow-x: hidden;
        overflow-y: auto;
        text-align: justify;
    }
</style>

@code {

    private int counter;

    private void OnScroll()
    {
        counter++;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM