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 5ca635c

Browse files
author
Brendan Mullins
authored
Merge pull request #25 from NicolasMrc/master
New Feature : Horizontal based parallax
2 parents 817ca46 + 07fbeb7 commit 5ca635c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ when using the `v-parallax` directive you can also pass some modifiers to config
4848
```
4949
| Modifier | Description |
5050
|---|---|
51+
| horizontal | horizontal based parallax |
5152
| centerX | will add `transform: translateX(-50%)` along with the parallax positioning |
5253
| absY | uses the window height instead of the element height for the calculations |

‎src/vue-parallax-js.js

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

4949
const height = mod.absY ? window.innerHeight : el.clientHeight || el.scrollHeight
50-
50+
const width = mod.absY ? window.innerWidth : el.clientWidth || el.scrollWidth
51+
5152
const cl = this.os.className
5253
if (typeof cl === 'string') {
5354
el.className = `${el.className} ${cl}`.trim()
@@ -61,6 +62,7 @@ ParallaxJS.prototype = {
6162
arg,
6263
mod,
6364
height,
65+
width,
6466
count: 0
6567
})
6668
},
@@ -71,6 +73,8 @@ ParallaxJS.prototype = {
7173
const n = t.currentStyle || window.getComputedStyle(t)
7274

7375
item.height = item.mod.absY ? window.innerHeight : t.clientHeight || t.scrollHeight
76+
item.width = item.mod.absX ? window.innerWidth : t.clientWidth || t.scrollWidth
77+
7478
if(t.offsetParent !== null)
7579
item.iOT = t.offsetTop + t.offsetParent.offsetTop - parseInt(n.marginTop)
7680

@@ -90,15 +94,18 @@ ParallaxJS.prototype = {
9094

9195
const sT = this.container ? this.container.scrollTop : window.scrollY || window.pageYOffset
9296
const wH = window.innerHeight
97+
const wW = window.innerWidth
9398

9499
this.items.forEach((item) => {
95100
const elH = item.height
101+
const elW = item.width
96102
const offset = item.iOT * -1 * item.value
97103
const pos = (((sT + wH) - (elH / 2) - (wH / 2)) * item.value) + offset
98-
104+
const posY = (((sT + wW) - (elW / 2) - (wW / 2)) * item.value) + offset
105+
99106
window.requestAnimationFrame(() => {
100107
const cx = item.mod.centerX ? '-50%' : '0px'
101-
const props = `translate3d(${cx},${pos.toFixed(3)}px,0px)`
108+
const props = !item.mod.horizontal ? `translate3d(${cx},${pos.toFixed(3)}px,0px)` : `translate3d(${posY.toFixed(3)}px,0px,0px)`
102109
item.el.style[this.tProp] = props
103110
})
104111
})

0 commit comments

Comments
(0)

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