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 e8f8aef

Browse files
author
Nicolas Mercier
committed
implemented horizontal parallax
1 parent 353f318 commit e8f8aef

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

‎src/vue-parallax-js.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ ParallaxJS.prototype = {
5353
if (style.display === 'none') return
5454

5555
const height = mod.absY ? window.innerHeight : el.clientHeight || el.scrollHeight
56-
56+
const width = mod.absY ? window.innerWidth : el.clientWidth || el.scrollWidth
57+
5758
const cl = this.os.className
5859
if (typeof cl === 'string') {
5960
el.className = `${el.className} ${cl}`.trim()
@@ -67,6 +68,7 @@ ParallaxJS.prototype = {
6768
arg,
6869
mod,
6970
height,
71+
width,
7072
count: 0
7173
})
7274
},
@@ -77,6 +79,8 @@ ParallaxJS.prototype = {
7779
const n = t.currentStyle || window.getComputedStyle(t)
7880

7981
item.height = item.mod.absY ? window.innerHeight : t.clientHeight || t.scrollHeight
82+
item.width = item.mod.absX ? window.innerWidth : t.clientWidth || t.scrollWidth
83+
8084
if(t.offsetParent !== null)
8185
item.iOT = t.offsetTop + t.offsetParent.offsetTop - parseInt(n.marginTop)
8286

@@ -96,15 +100,18 @@ ParallaxJS.prototype = {
96100

97101
const sT = this.container ? this.container.scrollTop : window.scrollY || window.pageYOffset
98102
const wH = window.innerHeight
103+
const wW = window.innerWidth
99104

100105
this.items.forEach((item) => {
101106
const elH = item.height
107+
const elW = item.width
102108
const offset = item.iOT * -1 * item.value
103109
const pos = (((sT + wH) - (elH / 2) - (wH / 2)) * item.value) + offset
104-
110+
const posY = (((sT + wW) - (elW / 2) - (wW / 2)) * item.value) + offset
111+
105112
window.requestAnimationFrame(() => {
106113
const cx = item.mod.centerX ? '-50%' : '0px'
107-
const props = `translate3d(${cx},${pos.toFixed(3)}px,0px)`
114+
const props = !item.mod.horizontal ? `translate3d(${cx},${pos.toFixed(3)}px,0px)` : `translate3d(${posY.toFixed(3)}px,0px,0px)`
108115
item.el.style[this.tProp] = props
109116
})
110117
})

0 commit comments

Comments
(0)

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