【发布时间】:2018-12-22 23:54:22
【问题描述】:
我正在学习 Vue,并且非常喜欢它。我有一个标签,我想在页面加载时将其固定在浏览器窗口的底部。当用户单击选项卡时,它会向上滑动以显示一些内容。
一切正常很棒。我可以让标签贴在页面底部 - 点击事件也很有效。
我遇到的问题是我需要计算标签(和div)的高度才能正确设置 CSS 属性。当页面加载时,您可以看到选项卡向下滑动到位。我想隐藏选项卡,直到所有内容都计算完毕并且位于正确的位置。
这是我正在使用的:
app.js
new Vue({
el: '#info',
delimiters: ['${', '}'],
data: {
active: false,
inactive: true,
styles: {
'bottom': 0
},
},
methods() {
toggle: function (event) {
event.preventDefault();
this.active = !this.active;
this.inactive = !this.inactive;
}
},
mounted() {
let tabHeight = this.$refs.infoTab.clientHeight;
let boxHeight = this.$refs.infoBox.clientHeight; // 473px
this.styles.bottom = -boxHeight + 'px';
}
});
HTML
<div class="info not-active" id="info" @click="toggle" ref="infoTab"
v-cloak
v-bind:class="{ active: active }"
v-bind:style="styles">
<!-- content -->
</div>
style.css
[v-cloak] {
display: none;
}
/* more classes */
.info {
width: 100%;
position: fixed;
&.inactive {
bottom: -100%;
}
&.active {
bottom: 0 !important;
}
}
我知道我很接近,我只是不希望用户看到标签滑入到位。它应该只是在那里。我尝试使用created 挂钩,但clientHeight 不可用。
非常感谢任何建议!
【问题讨论】:
标签: html css vue.js user-interface css-transitions