Skip to content

Commit 78d2edd

Browse files
committed
feat(MdApp): create reveal toolbars
1 parent 5cc5270 commit 78d2edd

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/components/MdApp/MdApp.vue

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
.md-app-toolbar {
8989
position: fixed;
9090
top: 0;
91+
transition: none;
9192
}
9293
}
9394
}

src/components/MdApp/MdAppMixin.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default {
3737
toolbar: {
3838
element: null,
3939
transformY: 0,
40-
hasElevation: true
40+
hasElevation: true,
41+
revealActive: false
4142
},
4243
drawer: {
4344
active: false,
@@ -95,11 +96,26 @@ export default {
9596
this.MdApp.toolbar.hasElevation = $event.target.scrollTop >= threshold
9697
},
9798
handleRevealMode ($event) {
98-
/* const height = this.MdApp.toolbar.element.offsetHeight
99-
const threshold = height + 10 */
99+
const toolbarHeight = this.MdApp.toolbar.element.offsetHeight
100+
const safeAmount = 10
101+
const threshold = toolbarHeight + safeAmount
100102
const scrollTop = $event.target.scrollTop
101103

102-
this.MdApp.toolbar.transformY = scrollTop
104+
window.clearTimeout(this.revealTimer)
105+
106+
this.revealTimer = window.setTimeout(() => {
107+
this.revealLastPos = scrollTop
108+
}, 100)
109+
110+
if (this.revealLastPos > scrollTop + safeAmount) {
111+
this.MdApp.toolbar.revealActive = true
112+
this.MdApp.toolbar.transformY = scrollTop - threshold
113+
} else if (scrollTop < threshold) {
114+
this.MdApp.toolbar.revealActive = false
115+
this.MdApp.toolbar.transformY = 0
116+
} else {
117+
this.MdApp.toolbar.transformY = scrollTop - threshold
118+
}
103119
},
104120
handleModeScroll ($event) {
105121
if (this.mdMode === 'reveal') {

src/components/MdApp/MdAppToolbar.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
computed: {
1212
toolbarClasses () {
1313
return {
14-
'md-no-elevation': !this.MdApp.toolbar.hasElevation
14+
'md-no-elevation': !this.MdApp.toolbar.hasElevation,
15+
'md-reveal-active': this.MdApp.toolbar.revealActive
1516
}
1617
},
1718
toolbarStyles () {
1819
return {
19-
transform: `translate3D(0, ${this.MdApp.toolbar.transformY}px, 0)`
20+
'margin-top': `${this.MdApp.toolbar.transformY}px`
2021
}
2122
}
2223
},
@@ -27,7 +28,16 @@
2728
</script>
2829

2930
<style lang="scss" scoped>
31+
@import "~components/MdAnimation/variables";
32+
3033
.md-no-elevation {
3134
box-shadow: none !important;
3235
}
36+
37+
.md-reveal .md-reveal-active {
38+
transform: translate3d(0, calc(100% + 10px), 0);
39+
transition: .3s $md-transition-stand-timing;
40+
transition-property: box-shadow, transform;
41+
will-change: box-shadow, transform;
42+
}
3343
</style>

0 commit comments

Comments
 (0)