Comparing version 0.1.1 to 0.2.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";var e=function(e){function t(){var t=document.querySelectorAll(e);t.length?Array.from(t,function(e){n(e)}):n(t)}function n(e){var t=o(),n=e.getAttribute("data-speed")||2;e.style.transform="translate3d(0px, "+t/n+"px, 0px)"}function o(){return void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop}var r=Object.create({init:function(){window.addEventListener("scroll",t)}});return r};exports.Paralless=e}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(this,function(){"use strict";exports.Paralless=function(e){function t(){!(arguments.length<=0||void 0===arguments[0])&&arguments[0];o=window.pageYOffset,i||(window.requestAnimationFrame(function(){return r.forEach(n)}),i=!0)}function n(e){var t=e.getAttribute("data-speed")||2;e.style.transform="translate3d(0px, "+scrollPosition/t+"px, 0px)"}var o=void 0,i=!1,r=[].slice.call(document.querySelectorAll(e)),c=Object.create({init:function(){window.addEventListener("scroll",t)}});return c}}); |
{ | ||
"name": "paralless", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Simple Parallax powered by CSS3 Transitions", | ||
@@ -8,4 +8,15 @@ "main": "dist/paralless.min.js", | ||
"scripts": { | ||
"build": "" | ||
"build": "mkdir -p dist && browserify src/paralless.js --standalone paralless > dist/paralless.browserify.js" | ||
}, | ||
"browserify": { | ||
"debug": true, | ||
"cache": {}, | ||
"packageCache": {}, | ||
"extension": [ | ||
"js" | ||
], | ||
"transform": [ | ||
"babelify" | ||
] | ||
}, | ||
"repository": { | ||
@@ -28,5 +39,8 @@ "type": "git", | ||
"devDependencies": { | ||
"babel-plugin-transform-object-rest-spread": "*", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-es2015-rollup": "*", | ||
"babel-plugin-transform-object-rest-spread": "*", | ||
"babelify": "^7.3.0", | ||
"browser-sync": "*", | ||
"browserify": "^13.1.0", | ||
"del": "*", | ||
@@ -33,0 +47,0 @@ "gulp": "*", |
@@ -0,30 +1,32 @@ | ||
export default (className) => { | ||
let y | ||
let tick = false | ||
let targets = [].slice.call(document.querySelectorAll(className)) | ||
let Paralless = (className) => { | ||
const instance = Object.create({ | ||
init: () => { | ||
window.addEventListener('scroll', handleScroll) | ||
const handler = e => { | ||
y = window.pageYOffset | ||
if (!tick) { | ||
window.requestAnimationFrame(() => targets.forEach(position)) | ||
tick = true | ||
} | ||
}) | ||
return instance | ||
function handleScroll() { | ||
let elms = document.querySelectorAll(className) | ||
elms.length ? Array.from(elms, (e) => { mI(e)}) : mI(elms) | ||
} | ||
function mI(el) { | ||
let scrollPosition = setPosition() | ||
const position = el => { | ||
let displace = el.getAttribute('data-speed') || 2 | ||
el.style.transform = "translate3d(0px, "+(scrollPosition / displace)+"px, 0px)" | ||
el.style.transform = `translate3d(0px, ${y / displace}px, 0px)` | ||
tick = false | ||
} | ||
function setPosition() { | ||
if (window.pageYOffset !== undefined) { | ||
return window.pageYOffset | ||
} else { | ||
return (document.documentElement || document.body.parentNode || document.body).scrollTop | ||
} | ||
const init = () => window.addEventListener('scroll', handler) | ||
const update = () => targets = [].slice.call(document.querySelectorAll(className)) | ||
const destroy = () => window.removeEventListener('scroll', handler) | ||
return { | ||
init, | ||
update, | ||
destroy | ||
} | ||
} | ||
exports.Paralless = Paralless |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
9897
9
167
15
3