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>
</li>
<ThumbNav class="thumb-nav thumb-nav--left mobile-hide"
:class="{ 'is-active': thumbRowOffsets[activeRow] >= 0 }"
:class="{ 'is-active': isLeftDesktopNavActive }"
direction="left"
@navClick="handleNavClickDesktop(activeRow, 'left')"/>
<ThumbNav class="thumb-nav thumb-nav--right mobile-hide"
:class="{ 'is-active': thumbRowOffsets[activeRow] > 0 }"
:class="{ 'is-active': thumbRowOffsets[activeRow] != 0 }"
direction="right"
@navClick="handleNavClickDesktop(activeRow, 'right')"/>
</ul>
@ -70,6 +70,8 @@ export default {
data () {
return {
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 () {
this.$nextTick(function () {
this.resetOffsets()
window.addEventListener('resize', this.resetOffsets)
this.initLeftNav()
})
window.addEventListener('resize', this.handleResize)
},
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() {
for (let index = 0; index < this.thumbRowOffsets.length; index++) {
this.$set(this.thumbRowOffsets, index, 0)
@ -114,13 +133,29 @@ export default {
offset += thumbContainerWidth
} else if (direction === 'right') {
offset -= thumbContainerWidth
if (offset != 0) {
this.isLeftDesktopNavActive = true
}
}
if (offset < 0) {
offset = 0
} else if (offset > maxOffset) {
} else if (offset >= maxOffset) {
offset = maxOffset
this.isLeftDesktopNavActive = false
}
this.$set(this.thumbRowOffsets, source, offset)
// this.isLeftDesktopNavActive
},
handleResize() {
if (!this.resizeIsThrottling) {
this.resizeIsThrottling = true
this.$nextTick(() => {
this.resetOffsets()
this.initLeftNav()
this.resizeIsThrottling = false
})
}
}
}
}