Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<parallax>
<img src="static/img/pexels-photo-241307.jpeg">
</parallax>
<parallax>
<img src="static/img/pexels-photo-3977529.jpg">
</parallax>
</div>
<div style="background-color: #fff; height: 100vh;"></div>
<h1>Parallax fixed position </h1>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Parallax.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
const parentHeight = this.$refs.block.offsetHeight
const parallaxHeight = this.$refs.parallax.offsetHeight
const availableOffset = parallaxHeight - parentHeight
let animationValue = (window.pageYOffset * this.speedFactor)
const scrollOffset = (this.$refs.block.offsetHeight - this.$refs.block.getBoundingClientRect().top)
let animationValue = (scrollOffset * this.speedFactor)

if (animationValue <= availableOffset && animationValue >= 0) {
this.el.style.transform = `translate3d(0, ${animationValue * this.directionValue}px ,0)`
Expand Down
Binary file added static/img/pexels-photo-3977529.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.