Skip to content

Fixed can't work if this component is used in sub container. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var ReactScrollPagination = _react2.default.createClass({
documentElement: _react.PropTypes.string, // The element selector which contains the list
paginationShowTime: _react.PropTypes.oneOfType([_react.PropTypes.number, // How long shall the pagination div shows
_react.PropTypes.string]),
excludeTopMargin: _react.PropTypes.oneOfType([_react.PropTypes.number, // The height value which should be excluded from scrollTop calculation
_react.PropTypes.string]),
excludeElement: _react.PropTypes.string, // The element selector which should be excluded from calculation
excludeHeight: _react.PropTypes.oneOfType([_react.PropTypes.number, // the height value which should be excluded from calculation
_react.PropTypes.string]),
Expand All @@ -45,11 +47,13 @@ var ReactScrollPagination = _react2.default.createClass({
isolate: {
onePageHeight: null,
timeoutFuncHandler: null,
excludeTopMargin: null,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malikid
Thanks so much for your pr, one question, is the prop excludeTopMargin works same as the prop excludeHeight, if so, maybe you can comment hte excludeHeight as deprecated.

excludeHeight: null,
triggerAt: null,
showTime: null,
defaultShowTime: 2000,
defaultTrigger: 30,
defaultExcludeTopMargin: 0,
defaultExcludeHeight: 0
},

Expand Down Expand Up @@ -113,6 +117,24 @@ var ReactScrollPagination = _react2.default.createClass({
return showTime;
},

getExcludeTopMargin: function getExcludeTopMargin() {
// 获取需要减去的高度
var excludeTopMargin = this.isolate.defaultExcludeTopMargin;

if (this.props.excludeTopMargin) {
var propsExcludeTopMargin = parseInt(this.props.excludeTopMargin);
if (isNaN(propsExcludeTopMargin)) {
console.error('WARNING: Failed to convert the props "excludeTopMargin" with value: "' + this.props.excludeTopMargin + '" to Number, please verify. Will take "' + this.isolate.defaultExcludeTopMargin + '" by default.');
} else {
excludeTopMargin = propsExcludeTopMargin;
}
}

this.isolate.excludeTopMargin = excludeTopMargin;

return excludeTopMargin;
},

getExcludeHeight: function getExcludeHeight() {
// 获取需要减去的高度
var excludeHeight = this.isolate.defaultExcludeHeight;
Expand Down Expand Up @@ -169,7 +191,7 @@ var ReactScrollPagination = _react2.default.createClass({
this.getOnePageHeight();

var windowHeight = jQuery(this.windowElement).height();
var scrollTop = jQuery(this.windowElement).scrollTop() + windowHeight - this.isolate.excludeHeight;
var scrollTop = jQuery(this.windowElement).scrollTop() + windowHeight - this.isolate.excludeHeight - this.isolate.excludeTopMargin;

if (this.isolate.onePageHeight !== null) {
var currentPage = Math.ceil(scrollTop / this.isolate.onePageHeight) || 1;
Expand All @@ -195,6 +217,7 @@ var ReactScrollPagination = _react2.default.createClass({

validateAndSetPropValues: function validateAndSetPropValues() {
this.isolate.triggerAt = this.getTriggerAt();
this.isolate.excludeTopMargin = this.getExcludeTopMargin();
this.isolate.excludeHeight = this.getExcludeHeight();
this.isolate.showTime = this.getShowTime();
},
Expand Down
29 changes: 28 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const ReactScrollPagination = React.createClass({
PropTypes.number, // How long shall the pagination div shows
PropTypes.string
]),
excludeTopMargin: PropTypes.oneOfType([
PropTypes.number, // The height value which should be excluded from scrollTop calculation
PropTypes.string
]),
excludeElement: PropTypes.string, // The element selector which should be excluded from calculation
excludeHeight: PropTypes.oneOfType([
PropTypes.number, // the height value which should be excluded from calculation
Expand All @@ -38,11 +42,13 @@ const ReactScrollPagination = React.createClass({
isolate: {
onePageHeight: null,
timeoutFuncHandler: null,
excludeTopMargin: null,
excludeHeight: null,
triggerAt: null,
showTime: null,
defaultShowTime: 2000,
defaultTrigger: 30,
defaultExcludeTopMargin: 0,
defaultExcludeHeight: 0
},

Expand Down Expand Up @@ -105,6 +111,26 @@ const ReactScrollPagination = React.createClass({
return showTime
},

getExcludeTopMargin: function () {
// 获取需要减去的高度
let excludeTopMargin = this.isolate.defaultExcludeTopMargin

if (this.props.excludeTopMargin) {
let propsExcludeTopMargin = parseInt(this.props.excludeTopMargin)
if (isNaN(propsExcludeTopMargin)) {
console.error('WARNING: Failed to convert the props "excludeTopMargin" with value: "' + this.props.excludeTopMargin +
'" to Number, please verify. Will take "' + this.isolate.defaultExcludeTopMargin + '" by default.')
} else {
excludeTopMargin = propsExcludeTopMargin
}

}

this.isolate.excludeTopMargin = excludeTopMargin

return excludeTopMargin
},

getExcludeHeight: function () {
// 获取需要减去的高度
let excludeHeight = this.isolate.defaultExcludeHeight
Expand Down Expand Up @@ -165,7 +191,7 @@ const ReactScrollPagination = React.createClass({
this.getOnePageHeight()

let windowHeight = jQuery(this.windowElement).height()
let scrollTop = jQuery(this.windowElement).scrollTop() + windowHeight - this.isolate.excludeHeight
let scrollTop = jQuery(this.windowElement).scrollTop() + windowHeight - this.isolate.excludeHeight - this.isolate.excludeTopMargin

if (this.isolate.onePageHeight !== null) {
let currentPage = Math.ceil(scrollTop / this.isolate.onePageHeight) || 1
Expand All @@ -191,6 +217,7 @@ const ReactScrollPagination = React.createClass({

validateAndSetPropValues: function () {
this.isolate.triggerAt = this.getTriggerAt()
this.isolate.excludeTopMargin = this.getExcludeTopMargin()
this.isolate.excludeHeight = this.getExcludeHeight()
this.isolate.showTime = this.getShowTime()
},
Expand Down