Skip to content

Commit

Permalink
add getCurFrameInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
zxmyunshipei committed Jun 2, 2015
1 parent 0013927 commit a240e31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var ClassNameMixin = require('./mixins/ClassNameMixin');
var Events = require('./utils/Events');
var debounce = require('./utils/debounce');
var domUtils = require('./utils/domUtils');
var getCurFrameInfo = require('./utils/getCurFrameInfo');

var Sticky = React.createClass({
mixins: [ClassNameMixin],
Expand Down Expand Up @@ -45,9 +46,11 @@ var Sticky = React.createClass({
this._init();
this.checkPosition();

this._scrollListener = Events.on(window, 'scroll',
var curWindow = getCurFrameInfo(React.findDOMNode(this.refs.sticker)).curWindow;

this._scrollListener = Events.on(curWindow, 'scroll',
debounce(this.checkPosition, 10).bind(this));
this._resizeListener = Events.on(window, 'resize',
this._resizeListener = Events.on(curWindow, 'resize',
debounce(this.checkPosition, 50).bind(this));
},

Expand Down
14 changes: 14 additions & 0 deletions src/utils/getCurFrameInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

function getCurFrameInfo(element) {

var curDocument = element.ownerDocument
var curWindow = 'defaultView' in curDocument ? curDocument.defaultView : curDocument.parentWindow

return {
curDocument: curDocument,
curWindow: curWindow
}
}

module.exports = getCurFrameInfo

0 comments on commit a240e31

Please sign in to comment.