universal-parallax
Advanced tools
Comparing version 1.0.12 to 1.0.13
/** | ||
* @version 1.0.12 | ||
* @version 1.0.13 | ||
* @author Marius Hansen <marius.o.hansen@gmail.com> | ||
@@ -9,2 +9,9 @@ * @license MIT | ||
// check if mobile | ||
if (/Mobi/.test(navigator.userAgent)) { | ||
windowHeight = screen.height; | ||
}else{ | ||
windowHeight = window.innerHeight; | ||
} | ||
// determine height | ||
@@ -14,3 +21,3 @@ function calculateHeight(parallax, speed) { | ||
var parentHeight = parallax[i].parentElement.scrollHeight; | ||
var elemOffsetTop = (window.innerHeight - parentHeight) / 2; | ||
var elemOffsetTop = (windowHeight - parentHeight) / 2; | ||
@@ -41,9 +48,3 @@ var bgHeight = parentHeight + ((elemOffsetTop - (elemOffsetTop / speed)) * 2); | ||
if (/Mobi/.test(navigator.userAgent)) { | ||
pageHeight = screen.height; | ||
}else{ | ||
pageHeight = window.innerHeight; | ||
} | ||
// determine height | ||
@@ -50,0 +51,0 @@ calculateHeight(parallax, speed); |
@@ -1,1 +0,1 @@ | ||
function calculateHeight(e,a){for(var t=0;e.length>t;t++){var n=e[t].parentElement.scrollHeight,l=(window.innerHeight-n)/2,i=n+2*(l-l/a);e[t].style.height=i+"px"}}function animateParallax(e,a){for(var t=0;e.length>t;t++){var n=e[t].parentElement.getBoundingClientRect().top/a;e[t].style.top=n+"px"}}var universalParallax=function(){this.init=function(e){void 0===e&&(e={}),e={speed:void 0!==e.speed?e.speed:4,className:void 0!==e.className?e.className:"parallax"};for(var a,t,n=document.getElementsByClassName(e.className),l=0;n.length>l;l++){var i=document.createElement("div");n[l].parentNode.insertBefore(i,n[l]),i.appendChild(n[l]);var r=n[l].parentElement;r.className+="parallax--container","relative"!==window.getComputedStyle(r.parentElement,null).getPropertyValue("position")&&(r.parentElement.style.position="relative");var s=n[l].dataset.parallaxImage;void 0!==s&&(n[l].style.backgroundImage="url("+s+")",1===n[l].classList.length&&"parallax"===n[l].classList[0]&&Object.assign(n[l].style,{"background-repeat":"no-repeat","background-position":"center","background-size":"cover"}))}a=n,(t=e.speed)<1.2&&(t=0),/Mobi/.test(navigator.userAgent)?pageHeight=screen.height:pageHeight=window.innerHeight,calculateHeight(a,t),window.addEventListener("resize",function(){calculateHeight(a,t)}),window.addEventListener("scroll",function(){animateParallax(a,t)})}}; | ||
function calculateHeight(e,a){for(var t=0;e.length>t;t++){var n=e[t].parentElement.scrollHeight,l=(windowHeight-n)/2,i=n+2*(l-l/a);e[t].style.height=i+"px"}}function animateParallax(e,a){for(var t=0;e.length>t;t++){var n=e[t].parentElement.getBoundingClientRect().top/a;e[t].style.top=n+"px"}}/Mobi/.test(navigator.userAgent)?windowHeight=screen.height:windowHeight=window.innerHeight;var universalParallax=function(){this.init=function(e){void 0===e&&(e={}),e={speed:void 0!==e.speed?e.speed:4,className:void 0!==e.className?e.className:"parallax"};for(var a,t,n=document.getElementsByClassName(e.className),l=0;n.length>l;l++){var i=document.createElement("div");n[l].parentNode.insertBefore(i,n[l]),i.appendChild(n[l]);var r=n[l].parentElement;r.className+="parallax--container","relative"!==window.getComputedStyle(r.parentElement,null).getPropertyValue("position")&&(r.parentElement.style.position="relative");var o=n[l].dataset.parallaxImage;void 0!==o&&(n[l].style.backgroundImage="url("+o+")",1===n[l].classList.length&&"parallax"===n[l].classList[0]&&Object.assign(n[l].style,{"background-repeat":"no-repeat","background-position":"center","background-size":"cover"}))}a=n,(t=e.speed)<1.2&&(t=0),calculateHeight(a,t),window.addEventListener("resize",function(){calculateHeight(a,t)}),window.addEventListener("scroll",function(){animateParallax(a,t)})}}; |
{ | ||
"name": "universal-parallax", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Easy parallax plugin using pure javascript. Also works on mobile platforms. Cross browser support.", | ||
@@ -5,0 +5,0 @@ "main": "dist/universal-parallax.js", |
# Universal Parallax | ||
Easy parallax plugin using pure javascript. Cross browser support, including mobile platforms. | ||
[See demo here](https://marrio-h.github.io/universal-parallax/demo/) | ||
[See demo](https://marrio-h.github.io/universal-parallax/demo/) | ||
## Features | ||
@@ -10,2 +11,3 @@ - Easy setup | ||
- Mobile phone support | ||
- Support for transparent backgrounds, without affecting content | ||
@@ -22,5 +24,5 @@ ## Install | ||
###### #2 | ||
Include this CSS file in your project `<link href="node_modules/universal-parallax/dist/universal-parallax.min.css" rel="stylesheet">` | ||
Or add this CSS | ||
Choose between either.. | ||
- Including `<link href="node_modules/universal-parallax/dist/universal-parallax.min.css" rel="stylesheet">` in your `<head>` section | ||
- Or adding this CSS | ||
```css | ||
@@ -27,0 +29,0 @@ .parallax--container { |
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
1819759
213
85