react-scroll
Advanced tools
Comparing version 1.0.24 to 1.1.0
@@ -97,2 +97,4 @@ "use strict"; | ||
var containerId = this.props.containerId; | ||
@@ -102,3 +104,5 @@ | ||
scrollSpy.mount(scrollSpyContainer); | ||
if(!scrollSpy.isMounted(scrollSpyContainer)) { | ||
scrollSpy.mount(scrollSpyContainer); | ||
} | ||
@@ -129,4 +133,4 @@ | ||
var offsetY = y - this.props.offset; | ||
var isInside = (offsetY >= elemTopBound && offsetY <= elemBottomBound); | ||
var isOutside = (offsetY < elemTopBound || offsetY > elemBottomBound); | ||
var isInside = (offsetY >= Math.floor(elemTopBound) && offsetY <= Math.floor(elemBottomBound)); | ||
var isOutside = (offsetY < Math.floor(elemTopBound) || offsetY > Math.floor(elemBottomBound)); | ||
var activeLink = scroller.getActiveLink(); | ||
@@ -151,3 +155,3 @@ | ||
scrollSpy.addSpyHandler(spyHandler); | ||
scrollSpy.addSpyHandler(spyHandler, scrollSpyContainer); | ||
} | ||
@@ -164,3 +168,3 @@ }, | ||
} else { | ||
className = this.props.className | ||
className = this.props.className; | ||
} | ||
@@ -167,0 +171,0 @@ |
@@ -19,2 +19,3 @@ var eventThrottler = function(eventHandler) { | ||
spySetState: [], | ||
scrollSpyContainers: [], | ||
@@ -27,5 +28,11 @@ mount: function (scrollSpyContainer) { | ||
}); | ||
this.scrollSpyContainers.push(scrollSpyContainer); | ||
scrollSpyContainer.addEventListener('scroll', eventHandler); | ||
} | ||
}, | ||
isMounted(scrollSpyContainer) { | ||
return this.scrollSpyContainers.indexOf(scrollSpyContainer) !== -1; | ||
}, | ||
currentPositionY: function (scrollSpyContainer) { | ||
@@ -43,4 +50,6 @@ if(scrollSpyContainer === document) { | ||
scrollHandler: function (scrollSpyContainer) { | ||
for(var i = 0; i < this.spyCallbacks.length; i++) { | ||
this.spyCallbacks[i](this.currentPositionY(scrollSpyContainer)); | ||
var callbacks = this.scrollSpyContainers[this.scrollSpyContainers.indexOf(scrollSpyContainer)].spyCallbacks; | ||
for(var i = 0; i < callbacks.length; i++) { | ||
var position =this.currentPositionY(scrollSpyContainer); | ||
callbacks[i](this.currentPositionY(scrollSpyContainer)); | ||
} | ||
@@ -53,4 +62,8 @@ }, | ||
addSpyHandler: function(handler){ | ||
this.spyCallbacks.push(handler); | ||
addSpyHandler: function(handler, scrollSpyContainer) { | ||
var container = this.scrollSpyContainers[this.scrollSpyContainers.indexOf(scrollSpyContainer)]; | ||
if(!container.spyCallbacks) { | ||
container.spyCallbacks = []; | ||
} | ||
container.spyCallbacks.push(handler); | ||
}, | ||
@@ -65,7 +78,16 @@ | ||
}, | ||
unmount: function () { | ||
this.spyCallbacks = []; | ||
for (var i = 0; i < this.scrollSpyContainers.length; i++) { | ||
this.scrollSpyContainers[i].spyCallbacks = []; | ||
} | ||
this.spySetState = []; | ||
document.removeEventListener('scroll', this.scrollHandler); | ||
}, | ||
update: function() { | ||
for (var i = 0; i < this.scrollSpyContainers.length; i++) { | ||
this.scrollHandler(this.scrollSpyContainers[i]); | ||
} | ||
} | ||
@@ -72,0 +94,0 @@ } |
{ | ||
"name": "react-scroll", | ||
"version": "1.0.24", | ||
"version": "1.1.0", | ||
"description": "A scroll component for React.js", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
@@ -35,3 +35,5 @@ ## React Scroll | ||
var scroll = Scroll.animateScroll; | ||
var scrollSpy = Scroll.scrollSpy; | ||
var Section = React.createClass({ | ||
@@ -48,2 +50,4 @@ componentDidMount: function() { | ||
scrollSpy.update(); | ||
}, | ||
@@ -304,2 +308,6 @@ componentWillUnmount: function() { | ||
> v1.1.0 | ||
- now possible to set initial active link on componentDidMount ( see README or examples code ) | ||
- removed unnecessary events for scroll. | ||
> v1.0.24 | ||
@@ -306,0 +314,0 @@ - you can now pass any native property to Link/Element |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38802
890
333