parallaxbro
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -1,28 +0,41 @@ | ||
module.exports = class Debug { | ||
'use strict'; | ||
init() { | ||
var $debugger; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
$('body').append('<span id="parallaxbroDebugger">0</span>'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
$debugger = $('#parallaxbroDebugger'); | ||
module.exports = function () { | ||
function Debug() { | ||
_classCallCheck(this, Debug); | ||
} | ||
$debugger.css({ | ||
'position': 'fixed', | ||
'top': '0', | ||
'right': '0', | ||
'font-size': '17px', | ||
'color': 'white', | ||
'background': 'black', | ||
'padding': '10px 12px', | ||
'z-index': '100000', | ||
'border-top-left-radius': '4px', | ||
'border-bottom-left-radius': '4px', | ||
}); | ||
_createClass(Debug, [{ | ||
key: 'init', | ||
value: function init() { | ||
var $debugger; | ||
setInterval(() => { | ||
$debugger.html(Math.round(window.pageYOffset)); | ||
}, 250); | ||
} | ||
$('body').append('<span id="parallaxbroDebugger">0</span>'); | ||
} | ||
$debugger = $('#parallaxbroDebugger'); | ||
$debugger.css({ | ||
'position': 'fixed', | ||
'top': '0', | ||
'right': '0', | ||
'font-size': '17px', | ||
'color': 'white', | ||
'background': 'black', | ||
'padding': '10px 12px', | ||
'z-index': '100000', | ||
'border-top-left-radius': '4px', | ||
'border-bottom-left-radius': '4px' | ||
}); | ||
setInterval(function () { | ||
$debugger.html(Math.round(window.pageYOffset)); | ||
}, 250); | ||
} | ||
}]); | ||
return Debug; | ||
}(); |
@@ -1,1 +0,3 @@ | ||
module.exports = require('./ParallaxBro'); | ||
'use strict'; | ||
module.exports = require('./ParallaxBro'); |
@@ -1,7 +0,13 @@ | ||
const ParallaxCollection = require('./ParallaxCollection'); | ||
const Debug = require('./debug'); | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var ParallaxCollection = require('./ParallaxCollection'); | ||
var Debug = require('./debug'); | ||
var $; | ||
module.exports = class ParalaxBro { | ||
module.exports = function () { | ||
@@ -11,9 +17,16 @@ /** | ||
*/ | ||
constructor(selector, height = '100%', options) { | ||
const {disableStyles, debug} = this._normalizeOptions(options); | ||
function ParallaxBro(selector) { | ||
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '100%'; | ||
var options = arguments[2]; | ||
_classCallCheck(this, ParallaxBro); | ||
var _normalizeOptions2 = this._normalizeOptions(options), | ||
disableStyles = _normalizeOptions2.disableStyles, | ||
debug = _normalizeOptions2.debug; | ||
this.collections = []; | ||
if (!selector) { | ||
throw 'You must pass a selector string to ParalaxBro.'; | ||
throw 'You must pass a selector string to ParallaxBro.'; | ||
} | ||
@@ -40,88 +53,121 @@ | ||
*/ | ||
addCollection(selector, options) { | ||
var collection; | ||
collection = new ParallaxCollection(selector, options); | ||
this.collections.push(collection); | ||
return collection; | ||
} | ||
unbind() { | ||
this._stopAnimationFrame = true; | ||
} | ||
_hydrateElements() { | ||
const posY = this.$el.doc.scrollTop() || 0; | ||
setTimeout(() => this._moveElements(0) , 0); | ||
if (posY > 0) { | ||
setTimeout(() => this._moveElements(posY) , 0); | ||
_createClass(ParallaxBro, [{ | ||
key: 'addCollection', | ||
value: function addCollection(selector, options) { | ||
var collection; | ||
collection = new ParallaxCollection(selector, options); | ||
this.collections.push(collection); | ||
return collection; | ||
} | ||
} | ||
}, { | ||
key: 'unbind', | ||
value: function unbind() { | ||
this._stopAnimationFrame = true; | ||
} | ||
}, { | ||
key: '_hydrateElements', | ||
value: function _hydrateElements() { | ||
var _this = this; | ||
/** | ||
* @param {String} wrapper | ||
*/ | ||
_cacheDOMElements(wrapper) { | ||
this.$el = {}; | ||
this.$el.win = $(window); | ||
this.$el.doc = $(document); | ||
this.$el.body = $('body'); | ||
this.$el.wrapper = $(wrapper); | ||
} | ||
var posY = this.$el.doc.scrollTop() || 0; | ||
setTimeout(function () { | ||
return _this._moveElements(0); | ||
}, 0); | ||
if (posY > 0) { | ||
setTimeout(function () { | ||
return _this._moveElements(posY); | ||
}, 0); | ||
} | ||
} | ||
_initDebug() { | ||
var debug; | ||
debug = new Debug(); | ||
debug.init(); | ||
} | ||
/** | ||
* @param {String} wrapper | ||
*/ | ||
_styleDOM(height) { | ||
var {body, wrapper, doc} = this.$el; | ||
doc.children().css('height', '100%'); | ||
body.css('height', '100%'); | ||
wrapper.css({ | ||
'height': height, | ||
'overflow': 'visible', | ||
'min-height': '100%', | ||
'box-sizing': 'border-box', | ||
}); | ||
wrapper.addClass('paralaxbro'); | ||
} | ||
}, { | ||
key: '_cacheDOMElements', | ||
value: function _cacheDOMElements(wrapper) { | ||
this.$el = {}; | ||
this.$el.win = $(window); | ||
this.$el.doc = $(document); | ||
this.$el.body = $('body'); | ||
this.$el.wrapper = $(wrapper); | ||
} | ||
}, { | ||
key: '_initDebug', | ||
value: function _initDebug() { | ||
var debug; | ||
debug = new Debug(); | ||
debug.init(); | ||
} | ||
}, { | ||
key: '_styleDOM', | ||
value: function _styleDOM(height) { | ||
var _$el = this.$el, | ||
body = _$el.body, | ||
wrapper = _$el.wrapper, | ||
doc = _$el.doc; | ||
_bindEvents() { | ||
const track = () => { | ||
if (this._stopAnimationFrame) { | ||
this._stopAnimationFrame = false; | ||
return; | ||
} | ||
var posY = window.pageYOffset; | ||
this._moveElements(posY); | ||
doc.children().css('height', '100%'); | ||
body.css('height', '100%'); | ||
wrapper.css({ | ||
'height': height, | ||
'overflow': 'visible', | ||
'min-height': '100%', | ||
'box-sizing': 'border-box' | ||
}); | ||
wrapper.addClass('parallaxbro'); | ||
} | ||
}, { | ||
key: '_bindEvents', | ||
value: function _bindEvents() { | ||
var _this2 = this; | ||
var track = function track() { | ||
if (_this2._stopAnimationFrame) { | ||
_this2._stopAnimationFrame = false; | ||
return; | ||
} | ||
var posY = window.pageYOffset; | ||
_this2._moveElements(posY); | ||
requestAnimationFrame(track); | ||
}; | ||
requestAnimationFrame(track); | ||
} | ||
requestAnimationFrame(track); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
_moveElements(posY) { | ||
var collections; | ||
collections = this.collections; | ||
collections.forEach(collection => collection.moveElements(posY)); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
_jQuery() { | ||
$ = jQuery; | ||
if (!$) { | ||
throw 'jQuery is not defined'; | ||
}, { | ||
key: '_moveElements', | ||
value: function _moveElements(posY) { | ||
var collections; | ||
collections = this.collections; | ||
collections.forEach(function (collection) { | ||
return collection.moveElements(posY); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: '_jQuery', | ||
value: function _jQuery() { | ||
$ = jQuery; | ||
if (!$) { | ||
throw 'jQuery is not defined'; | ||
} | ||
} | ||
}, { | ||
key: '_normalizeOptions', | ||
value: function _normalizeOptions(options) { | ||
return Object.assign({}, { | ||
disableStyles: false, | ||
height: '100%', | ||
debug: false | ||
}, options); | ||
} | ||
}]); | ||
_normalizeOptions(options) { | ||
return Object.assign({}, { | ||
disableStyles: false, | ||
height: '100%', | ||
debug: false, | ||
}, options); | ||
} | ||
} | ||
return ParallaxBro; | ||
}(); |
@@ -1,7 +0,16 @@ | ||
const {normalizeOptions, runUpdate} = require('./utils'); | ||
const ParallaxElement = require('./ParallaxElement'); | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _require = require('./utils'), | ||
normalizeOptions = _require.normalizeOptions, | ||
runUpdate = _require.runUpdate; | ||
var ParallaxElement = require('./ParallaxElement'); | ||
var $; | ||
module.exports = class ParallaxCollection { | ||
module.exports = function () { | ||
@@ -12,11 +21,18 @@ /** | ||
*/ | ||
constructor(selector, options) { | ||
function ParallaxCollection(selector, options) { | ||
_classCallCheck(this, ParallaxCollection); | ||
options = normalizeOptions(options, { | ||
top: {value: 0}, | ||
hide: {value: false}, | ||
zIndex: {value: -1}, | ||
update: {value: () => {}}, | ||
top: { value: 0 }, | ||
hide: { value: false }, | ||
zIndex: { value: -1 }, | ||
update: { value: function value() {} } | ||
}); | ||
const {top, hide, zIndex, update} = options; | ||
var _options = options, | ||
top = _options.top, | ||
hide = _options.hide, | ||
zIndex = _options.zIndex, | ||
update = _options.update; | ||
this.$el; | ||
@@ -38,105 +54,153 @@ this.elements = []; | ||
*/ | ||
addElements(obj) { | ||
var selectors, top, height; | ||
selectors = Object.keys(obj); | ||
height = 0; | ||
selectors.forEach(selector => { | ||
var options = obj[selector]; | ||
this._addElement(selector, options); | ||
height += $(selector).outerHeight(); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* @param {String} selector | ||
* @param {Object} options | ||
*/ | ||
_addElement(selector, options) { | ||
var element; | ||
element = new ParallaxElement(selector, options, this.top); | ||
this.elements.push(element); | ||
return this; | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
moveElements(posY) { | ||
var elements; | ||
elements = this.elements; | ||
this.runCallbacks(posY); | ||
elements.forEach(element => element.moveElement(posY)); | ||
this.yPrev = posY; | ||
} | ||
_createClass(ParallaxCollection, [{ | ||
key: 'addElements', | ||
value: function addElements(obj) { | ||
var _this = this; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
runCallbacks(posY) { | ||
this.updateHide(posY); | ||
this.updateZindex(posY); | ||
this.updateCallback(posY); | ||
} | ||
var selectors, top, height; | ||
selectors = Object.keys(obj); | ||
height = 0; | ||
selectors.forEach(function (selector) { | ||
var options = obj[selector]; | ||
_this._addElement(selector, options); | ||
height += $(selector).outerHeight(); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateHide(posY) { | ||
var prevY = this.yPrev; | ||
runUpdate(posY, prevY, this.hide, (value) => { | ||
this.hide.value = value; | ||
this.$el.css('opacity', value ? 0 : 1); | ||
}); | ||
} | ||
/** | ||
* @param {String} selector | ||
* @param {Object} options | ||
*/ | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateZindex(posY) { | ||
var prevY = this.yPrev; | ||
runUpdate(posY, prevY, this.zIndex, (value) => { | ||
this.zIndex.value = value; | ||
this.$el.css('zIndex', value); | ||
}); | ||
} | ||
}, { | ||
key: '_addElement', | ||
value: function _addElement(selector, options) { | ||
var element; | ||
element = new ParallaxElement(selector, options, this.top); | ||
this.elements.push(element); | ||
return this; | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateCallback(posY) { | ||
var yPrev, $el, self; | ||
yPrev = this.yPrev; | ||
$el = this.$el; | ||
self = this; | ||
runUpdate(posY, yPrev, this.update, (value, breakpoint) => { | ||
self.update.breakpoints[breakpoint].call(self, $el, posY, yPrev); | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
jQuery() { | ||
$ = jQuery; | ||
if (!$) { | ||
throw 'jQuery is not defined'; | ||
}, { | ||
key: 'moveElements', | ||
value: function moveElements(posY) { | ||
var elements; | ||
elements = this.elements; | ||
this.runCallbacks(posY); | ||
elements.forEach(function (element) { | ||
return element.moveElement(posY); | ||
}); | ||
this.yPrev = posY; | ||
} | ||
} | ||
/** | ||
* @param {String} selector | ||
* @param {Object} options | ||
*/ | ||
styleCollection(selector, options) { | ||
var $el, css; | ||
var {zIndex, hide} = options; | ||
css = {}; | ||
css.zIndex = zIndex.value; | ||
if (hide.value) { | ||
css.display = 'none'; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'runCallbacks', | ||
value: function runCallbacks(posY) { | ||
this.updateHide(posY); | ||
this.updateZindex(posY); | ||
this.updateCallback(posY); | ||
} | ||
$el = $(selector); | ||
$el.css(css); | ||
this.$el = $el; | ||
return this; | ||
} | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'updateHide', | ||
value: function updateHide(posY) { | ||
var _this2 = this; | ||
var prevY = this.yPrev; | ||
runUpdate(posY, prevY, this.hide, function (value) { | ||
_this2.hide.value = value; | ||
_this2.$el.css('opacity', value ? 0 : 1); | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'updateZindex', | ||
value: function updateZindex(posY) { | ||
var _this3 = this; | ||
var prevY = this.yPrev; | ||
runUpdate(posY, prevY, this.zIndex, function (value) { | ||
_this3.zIndex.value = value; | ||
_this3.$el.css('zIndex', value); | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'updateCallback', | ||
value: function updateCallback(posY) { | ||
var yPrev, $el, self; | ||
yPrev = this.yPrev; | ||
$el = this.$el; | ||
self = this; | ||
runUpdate(posY, yPrev, this.update, function (value, breakpoint) { | ||
self.update.breakpoints[breakpoint].call(self, $el, posY, yPrev); | ||
}); | ||
} | ||
}, { | ||
key: 'jQuery', | ||
value: function (_jQuery) { | ||
function jQuery() { | ||
return _jQuery.apply(this, arguments); | ||
} | ||
jQuery.toString = function () { | ||
return _jQuery.toString(); | ||
}; | ||
return jQuery; | ||
}(function () { | ||
$ = jQuery; | ||
if (!$) { | ||
throw 'jQuery is not defined'; | ||
} | ||
}) | ||
/** | ||
* @param {String} selector | ||
* @param {Object} options | ||
*/ | ||
}, { | ||
key: 'styleCollection', | ||
value: function styleCollection(selector, options) { | ||
var $el, css; | ||
var zIndex = options.zIndex, | ||
hide = options.hide; | ||
css = {}; | ||
css.zIndex = zIndex.value; | ||
if (hide.value) { | ||
css.display = 'none'; | ||
} | ||
$el = $(selector); | ||
$el.css(css); | ||
this.$el = $el; | ||
return this; | ||
} | ||
}]); | ||
return ParallaxCollection; | ||
}(); |
@@ -1,6 +0,15 @@ | ||
const {prefix, normalizeOptions, runUpdate} = require('./utils'); | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _require = require('./utils'), | ||
prefix = _require.prefix, | ||
normalizeOptions = _require.normalizeOptions, | ||
runUpdate = _require.runUpdate; | ||
var $; | ||
module.exports = class ParallaxElement { | ||
module.exports = function () { | ||
@@ -12,15 +21,25 @@ /** | ||
*/ | ||
constructor(selector, options, offsetTop) { | ||
function ParallaxElement(selector, options, offsetTop) { | ||
_classCallCheck(this, ParallaxElement); | ||
options = normalizeOptions(options, { | ||
top: {value: 0}, | ||
hide: {value: false}, | ||
zIndex: {value: -1}, | ||
speed: {value: 1}, | ||
center: {value: false}, | ||
update: {value: () => {}}, | ||
xFunc: {value: 0}, | ||
top: { value: 0 }, | ||
hide: { value: false }, | ||
zIndex: { value: -1 }, | ||
speed: { value: 1 }, | ||
center: { value: false }, | ||
update: { value: function value() {} }, | ||
xFunc: { value: 0 } | ||
}); | ||
const {top, hide, zIndex, speed, center, update, xFunc} = options; | ||
var _options = options, | ||
top = _options.top, | ||
hide = _options.hide, | ||
zIndex = _options.zIndex, | ||
speed = _options.speed, | ||
center = _options.center, | ||
update = _options.update, | ||
xFunc = _options.xFunc; | ||
this.$el; | ||
@@ -42,3 +61,3 @@ this.prefix = prefix(); | ||
this.jQuery(); | ||
this.styleElement(selector, {center, top}); | ||
this.styleElement(selector, { center: center, top: top }); | ||
} | ||
@@ -49,174 +68,230 @@ | ||
*/ | ||
moveElement(posY) { | ||
var $el, yPrev, tPrev, yNew, xNew, xFunc, func, speed, breakpoint, prevBreakpoint, delta, prefix | ||
this.runCallbacks(posY); | ||
yPrev = this.yPrev || 0; | ||
tPrev = this.tPrev || 0; | ||
prefix = this.prefix; | ||
xFunc = this.xFunc; | ||
$el = this.$el; | ||
speed = this.speed.value; | ||
breakpoint = this.speed._breakpoint; | ||
_createClass(ParallaxElement, [{ | ||
key: 'moveElement', | ||
value: function moveElement(posY) { | ||
var $el, yPrev, tPrev, yNew, xNew, xFunc, func, speed, breakpoint, prevBreakpoint, delta, prefix; | ||
if (breakpoint !== undefined) { | ||
let lastSpeed, yDiff; | ||
delta = 0; | ||
lastSpeed = this.speed._lastSpeed; | ||
this.runCallbacks(posY); | ||
yDiff = yPrev - breakpoint; | ||
delta += Math.round(yDiff*lastSpeed*100) / 100; | ||
yPrev = this.yPrev || 0; | ||
tPrev = this.tPrev || 0; | ||
prefix = this.prefix; | ||
xFunc = this.xFunc; | ||
$el = this.$el; | ||
speed = this.speed.value; | ||
breakpoint = this.speed._breakpoint; | ||
yDiff = breakpoint - posY; | ||
delta += Math.round(yDiff*speed*100) / 100; | ||
if (breakpoint !== undefined) { | ||
var lastSpeed = void 0, | ||
yDiff = void 0; | ||
delta = 0; | ||
lastSpeed = this.speed._lastSpeed; | ||
this.speed._breakpoint = undefined; | ||
yDiff = yPrev - breakpoint; | ||
delta += Math.round(yDiff * lastSpeed * 100) / 100; | ||
yDiff = breakpoint - posY; | ||
delta += Math.round(yDiff * speed * 100) / 100; | ||
this.speed._breakpoint = undefined; | ||
} else { | ||
var _yDiff = void 0; | ||
delta = 0; | ||
_yDiff = yPrev - posY; | ||
delta = Math.round(_yDiff * speed * 100) / 100; | ||
} | ||
yNew = tPrev + delta; | ||
func = xFunc.breakpoints[xFunc.value]; | ||
xNew = func ? func.call(null, posY - xFunc.value) : 0; | ||
$el[0].style[prefix.dom + 'Transform'] = 'translate3d(' + xNew + 'px, ' + yNew + 'px, 0) translateZ(0) scale(1)'; | ||
this.yPrev = posY; | ||
this.tPrev = yNew; | ||
return this; | ||
} | ||
else { | ||
let yDiff; | ||
delta = 0; | ||
yDiff = yPrev - posY; | ||
delta = Math.round(yDiff*speed*100) / 100; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'runCallbacks', | ||
value: function runCallbacks(posY) { | ||
this.updateHide(posY); | ||
this.updateZindex(posY); | ||
this.updateTop(posY); | ||
this.updateOffset(posY); | ||
this.updateSpeed(posY); | ||
this.updateXFunc(posY); | ||
this.updateCallback(posY); | ||
} | ||
yNew = tPrev + delta; | ||
func = xFunc.breakpoints[xFunc.value]; | ||
xNew = func ? func.call(null, posY - xFunc.value) : 0; | ||
$el[0].style[prefix.dom + 'Transform'] = `translate3d(${xNew}px, ${yNew}px, 0) translateZ(0) scale(1)`; | ||
this.yPrev = posY; | ||
this.tPrev = yNew; | ||
return this; | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
runCallbacks(posY) { | ||
this.updateHide(posY); | ||
this.updateZindex(posY); | ||
this.updateTop(posY); | ||
this.updateOffset(posY); | ||
this.updateSpeed(posY); | ||
this.updateXFunc(posY); | ||
this.updateCallback(posY); | ||
} | ||
}, { | ||
key: 'updateHide', | ||
value: function updateHide(posY) { | ||
var _this = this; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateHide(posY) { | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.hide, (value) => { | ||
this.hide.value = value; | ||
this.$el.css('display', value ? 'none' : 'block'); | ||
}); | ||
} | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.hide, function (value) { | ||
_this.hide.value = value; | ||
_this.$el.css('display', value ? 'none' : 'block'); | ||
}); | ||
} | ||
}, { | ||
key: 'updateZindex', | ||
value: function updateZindex(posY) { | ||
var _this2 = this; | ||
updateZindex(posY) { | ||
var prevY = this.yPrev; | ||
runUpdate(posY, prevY, this.zIndex, (value) => { | ||
this.zIndex.value = value; | ||
this.$el.css('zIndex', value); | ||
}); | ||
} | ||
var prevY = this.yPrev; | ||
runUpdate(posY, prevY, this.zIndex, function (value) { | ||
_this2.zIndex.value = value; | ||
_this2.$el.css('zIndex', value); | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateTop(posY) { | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.top, (value) => { | ||
var yOffset = this.yOffset; | ||
this.top.value = value = value + yOffset; | ||
this.$el.css('top', value + 'px'); | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateOffset(posY) { | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.offsetTop, (value) => { | ||
var yDiff, top; | ||
yDiff = value - this.yOffset; | ||
this.yOffset = value; | ||
top = parseInt(this.$el.css('top'), 10); | ||
this.$el.css('top', top + yDiff + 'px'); | ||
}); | ||
} | ||
}, { | ||
key: 'updateTop', | ||
value: function updateTop(posY) { | ||
var _this3 = this; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateSpeed(posY) { | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.speed, (value, breakpoint, scrollingDown, actualBreakpoint) => { | ||
this.speed._breakpoint = actualBreakpoint; | ||
this.speed._lastSpeed = this.speed.value; | ||
this.speed.value = value; | ||
}); | ||
} | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.top, function (value) { | ||
var yOffset = _this3.yOffset; | ||
_this3.top.value = value = value + yOffset; | ||
_this3.$el.css('top', value + 'px'); | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateXFunc(posY) { | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.xFunc, (value, breakpoint, scrollingDown, actualBreakpoint) => { | ||
this.xFunc.value = breakpoint; | ||
}); | ||
} | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
updateCallback(posY) { | ||
var yPrev, $el, self; | ||
yPrev = this.yPrev; | ||
$el = this.$el; | ||
self = this; | ||
runUpdate(posY, yPrev, this.update, (value, breakpoint) => { | ||
self.update.breakpoints[breakpoint].call(self, $el, posY, yPrev); | ||
}); | ||
} | ||
}, { | ||
key: 'updateOffset', | ||
value: function updateOffset(posY) { | ||
var _this4 = this; | ||
jQuery() { | ||
$ = jQuery; | ||
if (!$) { | ||
throw 'jQuery is not defined'; | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.offsetTop, function (value) { | ||
var yDiff, top; | ||
yDiff = value - _this4.yOffset; | ||
_this4.yOffset = value; | ||
top = parseInt(_this4.$el.css('top'), 10); | ||
_this4.$el.css('top', top + yDiff + 'px'); | ||
}); | ||
} | ||
return this; | ||
} | ||
/** | ||
* @param {String} selector | ||
* @param {Object} options | ||
*/ | ||
styleElement(selector, options) { | ||
var $el, css, yOffset; | ||
var {center, top} = options; | ||
yOffset = this.yOffset; | ||
css = { | ||
'position': 'fixed', | ||
'left': 0, | ||
'right': 0, | ||
}; | ||
if (center.value) { | ||
css['margin-right'] = 'auto'; | ||
css['margin-left'] = 'auto'; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'updateSpeed', | ||
value: function updateSpeed(posY) { | ||
var _this5 = this; | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.speed, function (value, breakpoint, scrollingDown, actualBreakpoint) { | ||
_this5.speed._breakpoint = actualBreakpoint; | ||
_this5.speed._lastSpeed = _this5.speed.value; | ||
_this5.speed.value = value; | ||
}); | ||
} | ||
if (top.value) { | ||
css.top = top + yOffset + 'px'; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'updateXFunc', | ||
value: function updateXFunc(posY) { | ||
var _this6 = this; | ||
var yPrev = this.yPrev; | ||
runUpdate(posY, yPrev, this.xFunc, function (value, breakpoint, scrollingDown, actualBreakpoint) { | ||
_this6.xFunc.value = breakpoint; | ||
}); | ||
} | ||
$el = $(selector); | ||
if (!$el.length) { | ||
throw `Invalid selector "${selector}"`; | ||
/** | ||
* @param {Number} posY | ||
*/ | ||
}, { | ||
key: 'updateCallback', | ||
value: function updateCallback(posY) { | ||
var yPrev, $el, self; | ||
yPrev = this.yPrev; | ||
$el = this.$el; | ||
self = this; | ||
runUpdate(posY, yPrev, this.update, function (value, breakpoint) { | ||
self.update.breakpoints[breakpoint].call(self, $el, posY, yPrev); | ||
}); | ||
} | ||
$el.css(css); | ||
this.$el = $el; | ||
return this; | ||
} | ||
}, { | ||
key: 'jQuery', | ||
value: function (_jQuery) { | ||
function jQuery() { | ||
return _jQuery.apply(this, arguments); | ||
} | ||
} | ||
jQuery.toString = function () { | ||
return _jQuery.toString(); | ||
}; | ||
return jQuery; | ||
}(function () { | ||
$ = jQuery; | ||
if (!$) { | ||
throw 'jQuery is not defined'; | ||
} | ||
return this; | ||
}) | ||
/** | ||
* @param {String} selector | ||
* @param {Object} options | ||
*/ | ||
}, { | ||
key: 'styleElement', | ||
value: function styleElement(selector, options) { | ||
var $el, css, yOffset; | ||
var center = options.center, | ||
top = options.top; | ||
yOffset = this.yOffset; | ||
css = { | ||
'position': 'fixed', | ||
'left': 0, | ||
'right': 0 | ||
}; | ||
if (center.value) { | ||
css['margin-right'] = 'auto'; | ||
css['margin-left'] = 'auto'; | ||
} | ||
if (top.value) { | ||
css.top = top + yOffset + 'px'; | ||
} | ||
$el = $(selector); | ||
if (!$el.length) { | ||
throw 'Invalid selector "' + selector + '"'; | ||
} | ||
$el.css(css); | ||
this.$el = $el; | ||
return this; | ||
} | ||
}]); | ||
return ParallaxElement; | ||
}(); |
@@ -1,21 +0,28 @@ | ||
const self = module.exports; | ||
'use strict'; | ||
self.callBreakpoints = (posY, yPrev, breakpoints, callback) => { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var self = module.exports; | ||
self.callBreakpoints = function (posY, yPrev, breakpoints, callback) { | ||
var scrollingDown, yDiff; | ||
scrollingDown = yPrev < posY; | ||
yDiff = scrollingDown ? posY - yPrev : yPrev - posY; | ||
breakpoints = breakpoints.map(breakpoint => parseInt(breakpoint, 10)); | ||
breakpoints = breakpoints.map(function (breakpoint) { | ||
return parseInt(breakpoint, 10); | ||
}); | ||
// @todo - we could use a different technique but this one works w/ little aparent downsides. | ||
for (let i=0; i<yDiff; i++) { | ||
let pos, index; | ||
for (var i = 0; i < yDiff; i++) { | ||
var pos = void 0, | ||
index = void 0; | ||
pos = scrollingDown ? yPrev + i : yPrev - i; | ||
index = breakpoints.indexOf(pos); | ||
if (index > -1) { | ||
let i = scrollingDown ? index : index - 1; | ||
callback.call(null, breakpoints[i], scrollingDown, breakpoints[index]); | ||
var _i = scrollingDown ? index : index - 1; | ||
callback.call(null, breakpoints[_i], scrollingDown, breakpoints[index]); | ||
} | ||
} | ||
} | ||
}; | ||
self.runUpdate = (posY, yPrev, obj, callback) => { | ||
self.runUpdate = function (posY, yPrev, obj, callback) { | ||
var breakpoints = Object.keys(obj.breakpoints); | ||
@@ -30,9 +37,11 @@ | ||
} | ||
self.callBreakpoints(posY, yPrev, breakpoints, (breakpoint, scrollingDown, actualBreakpoint) => { | ||
self.callBreakpoints(posY, yPrev, breakpoints, function (breakpoint, scrollingDown, actualBreakpoint) { | ||
var value = obj.breakpoints[breakpoint]; | ||
callback.call(null, value, breakpoint, scrollingDown, actualBreakpoint); | ||
}); | ||
} | ||
}; | ||
self.normalizeOptions = (options, defaults, exceptions = []) => { | ||
self.normalizeOptions = function (options, defaults) { | ||
var exceptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
var keys; | ||
@@ -45,3 +54,3 @@ | ||
keys.forEach(key => { | ||
keys.forEach(function (key) { | ||
var value, isObject; | ||
@@ -51,18 +60,17 @@ value = options[key]; | ||
if (isObject) { | ||
let value1 = value && value['0'] ? value['0'] : defaults[key].value; | ||
var value1 = value && value['0'] ? value['0'] : defaults[key].value; | ||
delete value.value; | ||
options[key] = { | ||
value: value1, | ||
breakpoints: Object.assign({}, {0: value1}, value), | ||
} | ||
} | ||
else { | ||
breakpoints: Object.assign({}, { 0: value1 }, value) | ||
}; | ||
} else { | ||
options[key] = { | ||
value, | ||
breakpoints: {0: value} | ||
} | ||
value: value, | ||
breakpoints: { 0: value } | ||
}; | ||
} | ||
}); | ||
return options; | ||
} | ||
}; | ||
@@ -77,3 +85,3 @@ /** | ||
*/ | ||
self.isType = (value, type) => { | ||
self.isType = function (value, type) { | ||
switch (type) { | ||
@@ -89,3 +97,3 @@ case 'string': | ||
case 'object': | ||
return typeof value === 'object' && value !== null && Array.isArray(value) === false; | ||
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null && Array.isArray(value) === false; | ||
case 'null': | ||
@@ -98,3 +106,3 @@ return value === null; | ||
case 'symbol': | ||
return typeof value === 'symbol'; | ||
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'symbol'; | ||
case 'NaN': | ||
@@ -105,21 +113,15 @@ return Number.isNaN(value); | ||
default: | ||
throw new Error(`Unrecgonized type: "${type}"`); | ||
throw new Error('Unrecgonized type: "' + type + '"'); | ||
} | ||
}; | ||
self.prefix = () => { | ||
self.prefix = function () { | ||
var styles, pre, dom; | ||
styles = window.getComputedStyle(document.documentElement, ''), | ||
pre = (Array.prototype.slice | ||
.call(styles) | ||
.join('') | ||
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o']) | ||
)[1], | ||
dom = ('webkit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1]; | ||
return { | ||
dom: dom, | ||
lowercase: pre, | ||
css: '-' + pre + '-', | ||
js: pre[0].toUpperCase() + pre.substr(1) | ||
}; | ||
}; | ||
styles = window.getComputedStyle(document.documentElement, ''), pre = (Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/) || styles.OLink === '' && ['', 'o'])[1], dom = 'webkit|Moz|MS|O'.match(new RegExp('(' + pre + ')', 'i'))[1]; | ||
return { | ||
dom: dom, | ||
lowercase: pre, | ||
css: '-' + pre + '-', | ||
js: pre[0].toUpperCase() + pre.substr(1) | ||
}; | ||
}; |
{ | ||
"name": "parallaxbro", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A powerful JS parallax framework", | ||
@@ -10,2 +10,5 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"build": "BABEL_ENV=commonjs babel src --out-dir lib", | ||
"prepublish": "npm run clean && npm run build", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -24,3 +27,3 @@ }, | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelify": "^7.3.0", | ||
@@ -27,0 +30,0 @@ "browser-sync": "^2.18.6", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24886
8
701
1