Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a6ee81

Browse files
Merge pull request #16 from 40818419/fix/ssr
fix(ssr): fixing server side rendering
2 parents 7fdaa65 + f977114 commit 5a6ee81

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

‎lib/vue-parallax-js.cjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/vue-parallax-js.es.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/vue-parallax-js.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/vue-parallax-js.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// @flow
2+
if (typeof window === 'undefined') {
3+
global.window = null
4+
}
5+
6+
if (typeof document === 'undefined') {
7+
global.document = null
8+
}
9+
210
const ParallaxJS = function (os) {
311
this.os = os
412
}
@@ -7,9 +15,9 @@ ParallaxJS.prototype = {
715
items: [],
816
active: true,
917

10-
tProp: window.transformProp || (function () {
11-
const testEl = document.createElement('div')
12-
if (testEl.style.transform == null) {
18+
tProp: window&&window.transformProp || (function () {
19+
const testEl = document ? document.createElement('div') : null
20+
if (testEl&&testEl.style.transform == null) {
1321
const vs = ['Webkit', 'Moz', 'ms']
1422
const t = 'Transform'
1523
for (const v of vs) {
@@ -22,6 +30,7 @@ ParallaxJS.prototype = {
2230
})(),
2331

2432
add (el, binding) {
33+
if (!window) return
2534
const value = binding.value
2635
const arg = binding.arg
2736
const style = el.currentStyle || window.getComputedStyle(el)
@@ -47,15 +56,17 @@ ParallaxJS.prototype = {
4756
count: 0
4857
})
4958
},
50-
update() {
51-
this.items.forEach(function(item) {
52-
let t = item.el;
53-
n = t.currentStyle || window.getComputedStyle(t);
59+
update () {
60+
if (!window) return
61+
this.items.forEach(function (item) {
62+
const t = item.el
63+
const n = t.currentStyle || window.getComputedStyle(t)
5464
item.height = item.mod.absY ? window.innerHeight : t.clientHeight || t.scrollHeight
5565
item.iOT = t.offsetTop + t.offsetParent.offsetTop - parseInt(n.marginTop)
5666
})
5767
},
5868
move () {
69+
if (!window) return
5970
if (!this.active) return
6071
if (window.innerWidth < this.os.minWidth || 0) {
6172
this.items.forEach((item) => {
@@ -84,7 +95,8 @@ ParallaxJS.prototype = {
8495

8596
export default {
8697
install (Vue, os = {}) {
87-
var p = new ParallaxJS(os)
98+
if (!window) return
99+
const p = new ParallaxJS(os)
88100

89101
window.addEventListener('scroll', () => {
90102
p.move(p)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /