mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
update code style
This commit is contained in:
parent
5cf7c592e1
commit
1705fd262a
@ -1,13 +1,13 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import rcUtil from 'rc-util';
|
||||
import { Dom } from 'rc-util';
|
||||
import classNames from 'classnames';
|
||||
|
||||
function getScroll(w, top) {
|
||||
let ret = w[`page${top ? 'Y' : 'X'}Offset`];
|
||||
let method = `scroll${top ? 'Top' : 'Left'}`;
|
||||
const method = `scroll${top ? 'Top' : 'Left'}`;
|
||||
if (typeof ret !== 'number') {
|
||||
let d = w.document;
|
||||
const d = w.document;
|
||||
// ie6,7,8 standard mode
|
||||
ret = d.documentElement[method];
|
||||
if (typeof ret !== 'number') {
|
||||
@ -19,42 +19,42 @@ function getScroll(w, top) {
|
||||
}
|
||||
|
||||
function getOffset(element) {
|
||||
let rect = element.getBoundingClientRect();
|
||||
let body = document.body;
|
||||
let clientTop = element.clientTop || body.clientTop || 0;
|
||||
let clientLeft = element.clientLeft || body.clientLeft || 0;
|
||||
let scrollTop = getScroll(window, true);
|
||||
let scrollLeft = getScroll(window);
|
||||
const rect = element.getBoundingClientRect();
|
||||
const body = document.body;
|
||||
const clientTop = element.clientTop || body.clientTop || 0;
|
||||
const clientLeft = element.clientLeft || body.clientLeft || 0;
|
||||
const scrollTop = getScroll(window, true);
|
||||
const scrollLeft = getScroll(window);
|
||||
|
||||
return {
|
||||
top: rect.top + scrollTop - clientTop,
|
||||
left: rect.left + scrollLeft - clientLeft
|
||||
left: rect.left + scrollLeft - clientLeft,
|
||||
};
|
||||
}
|
||||
|
||||
let Affix = React.createClass({
|
||||
const Affix = React.createClass({
|
||||
|
||||
getDefaultProps() {
|
||||
return {
|
||||
offset: 0
|
||||
offset: 0,
|
||||
};
|
||||
},
|
||||
|
||||
propTypes: {
|
||||
offset: React.PropTypes.number
|
||||
offset: React.PropTypes.number,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
affix: false,
|
||||
affixStyle: null
|
||||
affixStyle: null,
|
||||
};
|
||||
},
|
||||
|
||||
handleScroll() {
|
||||
let affix = this.state.affix;
|
||||
let scrollTop = getScroll(window, true);
|
||||
let elemOffset = getOffset(ReactDOM.findDOMNode(this));
|
||||
const affix = this.state.affix;
|
||||
const scrollTop = getScroll(window, true);
|
||||
const elemOffset = getOffset(ReactDOM.findDOMNode(this));
|
||||
|
||||
if (!affix && (elemOffset.top - this.props.offset) < scrollTop) {
|
||||
this.setState({
|
||||
@ -62,22 +62,22 @@ let Affix = React.createClass({
|
||||
affixStyle: {
|
||||
top: this.props.offset,
|
||||
left: elemOffset.left,
|
||||
width: ReactDOM.findDOMNode(this).offsetWidth
|
||||
}
|
||||
width: ReactDOM.findDOMNode(this).offsetWidth,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (affix && (elemOffset.top - this.props.offset) > scrollTop) {
|
||||
this.setState({
|
||||
affix: false,
|
||||
affixStyle: null
|
||||
affixStyle: null,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
this.scrollEvent = rcUtil.Dom.addEventListener(window, 'scroll', this.handleScroll);
|
||||
this.resizeEvent = rcUtil.Dom.addEventListener(window, 'resize', this.handleScroll);
|
||||
this.scrollEvent = Dom.addEventListener(window, 'scroll', this.handleScroll);
|
||||
this.resizeEvent = Dom.addEventListener(window, 'resize', this.handleScroll);
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
@ -92,7 +92,7 @@ let Affix = React.createClass({
|
||||
render() {
|
||||
const className = classNames({
|
||||
[this.props.className]: this.props.className,
|
||||
'ant-affix': this.state.affix
|
||||
'ant-affix': this.state.affix,
|
||||
});
|
||||
|
||||
return (
|
||||
@ -102,7 +102,7 @@ let Affix = React.createClass({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
.ant-affix {
|
||||
position: fixed;
|
||||
z-index: 10;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user