Skip to content

Commit

Permalink
bug fix for #54
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Dec 31, 2016
1 parent dbd118f commit a939dbd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/components/parallax/Parallax.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
div(
class="parallax"
v-bind:style="{ minHeight: this.height + 'px' }"
v-bind:style="{ minHeight: this.normalizedHeight + 'px' }"
)
div(class="parallax__image-container")
img(
Expand Down Expand Up @@ -47,7 +47,6 @@
methods: {
init () {
if (this.$refs.img.complete) {
console.log('here')
this.translate()
this.listeners()
return this.$vuetify.bus.pub('parallax:ready')
Expand All @@ -57,7 +56,7 @@
this.translate()
this.listeners()
this.$vuetify.bus.pub('parallax:ready')
}, { once: true })
}, false)
},
objHeight () {
Expand Down
43 changes: 26 additions & 17 deletions src/mixins/translatable.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
export default {
data () {
return {
obj_height: null,
parallax: null,
parallax_dist: null,
bottom: null,
top: null,
scroll_top: null,
window_height: null,
window_bottom: null
parallaxDist: null,
elOffsetTop: null,
percentScrolled: null,
scrollTop: null,
windowHeight: null,
windowBottom: null
}
},

computed: {
normalizedHeight () {
return Number(this.height.toString().replace(/(^[0-9]*$)/, '$1'))
},

imgHeight () {
return this.objHeight()
}
},

Expand All @@ -30,25 +39,25 @@ export default {
translate () {
this.calcDimensions()

let percent_scrolled = (
(this.window_bottom - this.top) / (Number(this.height) + this.window_height)
this.percentScrolled = (
(this.windowBottom - this.elOffsetTop) / (this.normalizedHeight + this.windowHeight)
)

this.parallax = Math.round(this.parallax_dist * percent_scrolled)
this.parallax = Math.round(this.parallaxDist * this.percentScrolled)

if (this.translated) {
this.translated()
}
},

calcDimensions () {
this.obj_height = this.objHeight()
this.parallax_dist = this.obj_height - this.height
this.top = this.elOffsetTop()
this.bottom = this.top + this.height
this.scroll_top = window.pageYOffset
this.window_height = window.innerHeight
this.window_bottom = this.scroll_top + this.window_height
let offset = this.$el.getBoundingClientRect()

this.scrollTop = window.pageYOffset
this.parallaxDist = this.imgHeight - this.normalizedHeight
this.elOffsetTop = offset.top + this.scrollTop
this.windowHeight = window.innerHeight
this.windowBottom = this.scrollTop + this.windowHeight
}
}
}

0 comments on commit a939dbd

Please sign in to comment.