react-scroll
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -9,7 +9,7 @@ "use strict"; | ||
var requestAnimationFrame = (function () { | ||
return window.requestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
function (callback, element, delay) { | ||
window.setTimeout(callback, delay || (1000/60)); | ||
}; | ||
return window.requestAnimationFrame || | ||
window.webkitRequestAnimationFrame || | ||
function (callback, element, delay) { | ||
window.setTimeout(callback, delay || (1000/60)); | ||
}; | ||
})(); | ||
@@ -24,126 +24,124 @@ | ||
var currentPositionY = function() { | ||
var supportPageOffset = window.pageXOffset !== undefined; | ||
var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat"); | ||
__currentPositionY = supportPageOffset ? window.pageYOffset : isCSS1Compat ? | ||
document.documentElement.scrollTop : document.body.scrollTop; | ||
return __currentPositionY; | ||
var supportPageOffset = window.pageXOffset !== undefined; | ||
var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat"); | ||
__currentPositionY = supportPageOffset ? window.pageYOffset : isCSS1Compat ? | ||
document.documentElement.scrollTop : document.body.scrollTop; | ||
return __currentPositionY; | ||
}; | ||
var setDirection = function() { | ||
__direction = __targetPositionY > __currentPositionY ? "down" : "up"; | ||
__direction = __targetPositionY > __currentPositionY ? "down" : "up"; | ||
}; | ||
var animateTopScroll = function(y) { | ||
switch(__direction) { | ||
case "down": | ||
__currentPositionY = __currentPositionY + __speed; | ||
if(__currentPositionY >= __targetPositionY) { | ||
console.log(__targetPositionY, __currentPositionY); | ||
window.scrollTo(0, __targetPositionY); | ||
return; | ||
} | ||
break; | ||
case "up": | ||
__currentPositionY = __currentPositionY - __speed; | ||
if(__currentPositionY <= __targetPositionY) { | ||
console.log(__targetPositionY, __currentPositionY); | ||
window.scrollTo(0, __targetPositionY); | ||
return; | ||
} | ||
break; | ||
} | ||
switch(__direction) { | ||
case "down": | ||
__currentPositionY = __currentPositionY + __speed; | ||
if(__currentPositionY >= __targetPositionY) { | ||
window.scrollTo(0, __targetPositionY); | ||
return; | ||
} | ||
break; | ||
case "up": | ||
__currentPositionY = __currentPositionY - __speed; | ||
if(__currentPositionY <= __targetPositionY) { | ||
window.scrollTo(0, __targetPositionY); | ||
return; | ||
} | ||
break; | ||
} | ||
window.scrollTo(0, __currentPositionY); | ||
window.scrollTo(0, __currentPositionY); | ||
requestAnimationFrame(animateTopScroll); | ||
requestAnimationFrame(animateTopScroll); | ||
}; | ||
var startAnimateTopScroll = function(y) { | ||
__targetPositionY = y; | ||
currentPositionY(); | ||
__targetPositionY = __targetPositionY + __currentPositionY | ||
setDirection(); | ||
__targetPositionY = y; | ||
currentPositionY(); | ||
__targetPositionY = __targetPositionY + __currentPositionY | ||
setDirection(); | ||
requestAnimationFrame(animateTopScroll); | ||
requestAnimationFrame(animateTopScroll); | ||
}; | ||
var Helpers = { | ||
Scroll: { | ||
propTypes: { | ||
to: React.PropTypes.string.isRequired | ||
}, | ||
scrollTo : function(to) { | ||
/* | ||
* get the mapped DOM element | ||
*/ | ||
Scroll: { | ||
propTypes: { | ||
to: React.PropTypes.string.isRequired | ||
}, | ||
scrollTo : function(to) { | ||
/* | ||
* get the mapped DOM element | ||
*/ | ||
var target = __mapped[to]; | ||
if(!target) { | ||
throw new Error("target Element not found"); | ||
} | ||
var target = __mapped[to]; | ||
if(!target) { | ||
throw new Error("target Element not found"); | ||
} | ||
var cordinates = target.getBoundingClientRect(); | ||
var cordinates = target.getBoundingClientRect(); | ||
/* | ||
* if smooth is not provided just scroll into the view | ||
*/ | ||
/* | ||
* if smooth is not provided just scroll into the view | ||
*/ | ||
if(!this.props.smooth) { /* Should look into browser compability for this one*/ | ||
window.scrollTo(0, cordinates.top); | ||
return; | ||
} | ||
if(!this.props.smooth) { /* Should look into browser compability for this one*/ | ||
window.scrollTo(0, cordinates.top); | ||
return; | ||
} | ||
/* | ||
* Animate scrolling | ||
*/ | ||
var options = {}; | ||
/* | ||
* Animate scrolling | ||
*/ | ||
var options = {}; | ||
startAnimateTopScroll(cordinates.top, options); | ||
startAnimateTopScroll(cordinates.top, options); | ||
}, | ||
onClick: function() { | ||
/* | ||
* give the posibility to override onClick | ||
*/ | ||
if(this.props.onClick) { | ||
this.props.onClick(event); | ||
} | ||
}, | ||
onClick: function() { | ||
/* | ||
* give the posibility to override onClick | ||
*/ | ||
if(this.props.onClick) { | ||
this.props.onClick(event); | ||
} | ||
/* | ||
* dont bubble the navigation | ||
*/ | ||
/* | ||
* dont bubble the navigation | ||
*/ | ||
if (event.stopPropagation) event.stopPropagation(); | ||
if (event.preventDefault) event.preventDefault(); | ||
if (event.stopPropagation) event.stopPropagation(); | ||
if (event.preventDefault) event.preventDefault(); | ||
/* | ||
* do the magic! | ||
*/ | ||
/* | ||
* do the magic! | ||
*/ | ||
this.scrollTo(this.props.to); | ||
this.scrollTo(this.props.to); | ||
}, | ||
componentDidMount: function() { | ||
} | ||
}, | ||
Element: { | ||
propTypes: { | ||
name: React.PropTypes.string.isRequired | ||
}, | ||
componentDidMount: function() { | ||
__mapped[this.props.name] = this.getDOMNode(); | ||
} | ||
}, | ||
Spy: { | ||
componentDidMount: function() { | ||
} | ||
} | ||
}, | ||
componentDidMount: function() { | ||
} | ||
}, | ||
Element: { | ||
propTypes: { | ||
name: React.PropTypes.string.isRequired | ||
}, | ||
componentDidMount: function() { | ||
__mapped[this.props.name] = this.getDOMNode(); | ||
} | ||
}, | ||
Spy: { | ||
componentDidMount: function() { | ||
} | ||
} | ||
}; | ||
@@ -150,0 +148,0 @@ |
{ | ||
"name": "react-scroll", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "A scroll component for React.js", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
6492
6
0
97
148