About the use of scrollTop

problem description

use $(".scroll _ center"). ScrollTop (0) in our angular project; failed to top the scroll bar, which is a pop-up scroll bar

the environmental background of the problems and what methods you have tried

this element is a pop-up box, and then solved with a timer, you can set it to the top, but the loading mode of this js is somewhat unknown. Which god can answer it? thank you very much

.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

    $timeout(function(){
        $(".dialog_center").scrollTop(0);
    })

what result do you expect? What is the error message actually seen?

Apr.05,2021

timeout is added to the task queue, delaying execution.
may be that your pop-up box has an animation effect, so that the element $('.pop _ center') is not available the first time. You can try to remove the timeout and print out $('.blank _ center') to see if it is empty.


your problem flow is not fully described and can only be guessed.

  1. using $('.rendering _ center'). ScrollTop (0) does not work, most likely because there is no such object as class _ center on the page at this time, and the reason is that the process of rendering dom on the page is not finished yet.
  2. is placed in timeout, and it will be executed immediately after the current process is idle (Angular should have done Dom rendering work before). At this time, all the page elements can be found and manipulated directly, so it can achieve the desired effect
  3. .
Menu