Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vue-parallax-js.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/vue-parallax-js.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/vue-parallax-js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions src/vue-parallax-js.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
// @flow
if (typeof window === 'undefined') {
global.window = null
}

if (typeof document === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point for mutating the global variable to null when they're undefined?

global.document = null
}

const ParallaxJS = function (os) {
this.os = os
}
Expand All @@ -7,9 +15,9 @@ ParallaxJS.prototype = {
items: [],
active: true,

tProp: window.transformProp || (function () {
const testEl = document.createElement('div')
if (testEl.style.transform == null) {
tProp: window && window.transformProp || (function () {
const testEl = document ? document.createElement('div') : null
if (testEl && testEl.style.transform == null) {
const vs = ['Webkit', 'Moz', 'ms']
const t = 'Transform'
for (const v of vs) {
Expand All @@ -22,6 +30,7 @@ ParallaxJS.prototype = {
})(),

add (el, binding) {
if (!window) return
const value = binding.value
const arg = binding.arg
const style = el.currentStyle || window.getComputedStyle(el)
Expand All @@ -47,15 +56,17 @@ ParallaxJS.prototype = {
count: 0
})
},
update() {
this.items.forEach(function(item) {
let t = item.el;
n = t.currentStyle || window.getComputedStyle(t);
update () {
if (!window) return
this.items.forEach(function (item) {
const t = item.el
const n = t.currentStyle || window.getComputedStyle(t)
item.height = item.mod.absY ? window.innerHeight : t.clientHeight || t.scrollHeight
item.iOT = t.offsetTop + t.offsetParent.offsetTop - parseInt(n.marginTop)
})
},
move () {
if (!window) return
if (!this.active) return
if (window.innerWidth < this.os.minWidth || 0) {
this.items.forEach((item) => {
Expand Down Expand Up @@ -84,7 +95,8 @@ ParallaxJS.prototype = {

export default {
install (Vue, os = {}) {
var p = new ParallaxJS(os)
if (!window) return
const p = new ParallaxJS(os)

window.addEventListener('scroll', () => {
p.move(p)
Expand Down