gallery thumb behaviour fully implemented

This commit is contained in:
ManjaroOne666 2019-01-09 19:55:19 +00:00
parent f083194c56
commit d2f0af9e98
1 changed files with 39 additions and 4 deletions

View File

@ -33,11 +33,11 @@
</ul> </ul>
</li> </li>
<ThumbNav class="thumb-nav thumb-nav--left mobile-hide" <ThumbNav class="thumb-nav thumb-nav--left mobile-hide"
:class="{ 'is-active': thumbRowOffsets[activeRow] >= 0 }" :class="{ 'is-active': isLeftDesktopNavActive }"
direction="left" direction="left"
@navClick="handleNavClickDesktop(activeRow, 'left')"/> @navClick="handleNavClickDesktop(activeRow, 'left')"/>
<ThumbNav class="thumb-nav thumb-nav--right mobile-hide" <ThumbNav class="thumb-nav thumb-nav--right mobile-hide"
:class="{ 'is-active': thumbRowOffsets[activeRow] > 0 }" :class="{ 'is-active': thumbRowOffsets[activeRow] != 0 }"
direction="right" direction="right"
@navClick="handleNavClickDesktop(activeRow, 'right')"/> @navClick="handleNavClickDesktop(activeRow, 'right')"/>
</ul> </ul>
@ -70,6 +70,8 @@ export default {
data () { data () {
return { return {
thumbRowOffsets: new Array(this.galleries.length), thumbRowOffsets: new Array(this.galleries.length),
isLeftDesktopNavActive: false,
resizeIsThrottling: false
} }
}, },
@ -80,14 +82,31 @@ export default {
} }
}, },
watch: {
activeRow: function(val) {
this.$nextTick(() => {
this.initLeftNav()
})
}
},
mounted () { mounted () {
this.$nextTick(function () { this.$nextTick(function () {
this.resetOffsets() this.resetOffsets()
window.addEventListener('resize', this.resetOffsets) this.initLeftNav()
}) })
window.addEventListener('resize', this.handleResize)
}, },
methods: { methods: {
initLeftNav () {
let offset = this.thumbRowOffsets[this.activeRow]
let totalRowWidth = this.$refs.galleryThumbsRowContainers[this.activeRow].clientWidth
let visibleRowWidth = this.$refs.galleryThumbsList.clientWidth
let maxOffset = totalRowWidth - visibleRowWidth
this.isLeftDesktopNavActive = (totalRowWidth > visibleRowWidth)
&& (offset < maxOffset)
},
resetOffsets() { resetOffsets() {
for (let index = 0; index < this.thumbRowOffsets.length; index++) { for (let index = 0; index < this.thumbRowOffsets.length; index++) {
this.$set(this.thumbRowOffsets, index, 0) this.$set(this.thumbRowOffsets, index, 0)
@ -114,13 +133,29 @@ export default {
offset += thumbContainerWidth offset += thumbContainerWidth
} else if (direction === 'right') { } else if (direction === 'right') {
offset -= thumbContainerWidth offset -= thumbContainerWidth
if (offset != 0) {
this.isLeftDesktopNavActive = true
}
} }
if (offset < 0) { if (offset < 0) {
offset = 0 offset = 0
} else if (offset > maxOffset) { } else if (offset >= maxOffset) {
offset = maxOffset offset = maxOffset
this.isLeftDesktopNavActive = false
} }
this.$set(this.thumbRowOffsets, source, offset) this.$set(this.thumbRowOffsets, source, offset)
// this.isLeftDesktopNavActive
},
handleResize() {
if (!this.resizeIsThrottling) {
this.resizeIsThrottling = true
this.$nextTick(() => {
this.resetOffsets()
this.initLeftNav()
this.resizeIsThrottling = false
})
}
} }
} }
} }