From a240e319da89d56e62daec4f1c807dcbc86fe347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=93=E8=90=8C?= Date: Tue, 2 Jun 2015 17:59:32 +0800 Subject: [PATCH] add getCurFrameInfo --- src/Sticky.js | 7 +++++-- src/utils/getCurFrameInfo.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/utils/getCurFrameInfo.js diff --git a/src/Sticky.js b/src/Sticky.js index 6d41622..d62595a 100644 --- a/src/Sticky.js +++ b/src/Sticky.js @@ -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], @@ -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)); }, diff --git a/src/utils/getCurFrameInfo.js b/src/utils/getCurFrameInfo.js new file mode 100644 index 0000000..51eb1ca --- /dev/null +++ b/src/utils/getCurFrameInfo.js @@ -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 \ No newline at end of file