When doing a project, you need to set the scrolltop of a hidden element and then display it. The use of jquery scrolltop method, but ineffective, Baidu for a long time, still can not find an effective solution. So I created a new Web page to test the reasons for the failure of ScrollTop method, after a toss, finally understand the cause of the problem and solutions.
The cause of scrolltop failure
When an element's display property is ' None ', setting the ScrollTop property on the element is not valid, so even the jquery scrolltop method will not work.
Solutions
Setting the element to the visible state (el.style.display= ' block '), you can set the native El.scrolltop property or the ScrollTop method of jquery.
Experience: To go online to find a solution to the problem is not a panacea, more often still need to do their own step-by-step debugging, and then get a solution.