巧用生命周期, 选择在 before 或 after 插入元素
Open
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
componentDidUpdate: function() {
var node = this.getDOMNode();
node.scrollTop = node.scrollHeight;
},
仅当用户已经滚到底时执行策略
componentWillUpdate: function() {
var node = this.getDOMNode();
this.shouldScrollBottom = node.scrollTop + node.offsetHeight === node.scrollHeight;
},
componentDidUpdate: function() {
if (this.shouldScrollBottom) {
var node = this.getDOMNode();
node.scrollTop = node.scrollHeight
}
},
Insertion at the top
componentWillUpdate: function() {
var node = this.getDOMNode();
this.scrollHeight = node.scrollHeight;
this.scrollTop = node.scrollTop;
},
componentDidUpdate: function() {
var node = this.getDOMNode();
node.scrollTop = this.scrollTop + (node.scrollHeight - this.scrollHeight);
},
ref: http://blog.vjeux.com/2013/javascript/scroll-position-with-react.html
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides React lifecycle JSX examples for preserving scroll position and links to a reference article, but it names no repository file, test, or requested change. First determine where this tip belongs and what documentation format is expected; done should be defined by an agreed placement and a reviewed, accurate explanation of the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100