【发布时间】:2017-10-07 23:58:28
【问题描述】:
我在我的用例中遇到了Vue-multipane 组件的问题,我没有找到解决方案。
一旦屏幕尺寸小于 768 像素,我会尝试禁用多窗格并显示全宽行而不是列。所以我的页面在移动设备上更好用。
现在我有两个问题:
- 如果屏幕尺寸低于 768 像素,则缩小的窗格不会最大化到 100%(请参见下面的屏幕截图)。所以先用句柄减小窗格的宽度,然后将窗口宽度减小到断点 786px 以下即可看到上述行为。
- 如果将屏幕尺寸减小到 768 - 770 像素(接近分页符),句柄将不可见。分页符未激活,但句柄不可见。不知道出了什么问题 - 也许这很容易解决,但我还没有找到方法。
(缺少句柄)
缩小到 767 像素(应该最大化到 100%) - 缩小窗格而不是缩小窗口宽度:
它应该看起来像这样(在页面加载时它会正确显示):
请查看fiddle 或下面的代码。
但最好使用 jsfiddle,因为它更容易调整大小和测试上述行为。
我尝试解决的问题:
- 将 css 样式
flex-grow: 1和width: 100%;添加到left-pane的媒体查询中,但这不起作用。 - 对于句柄问题:我稍微更改了断点位置,但行为仍然存在。
注意:我已经用 Firefox 测试过代码。
//console.log(Multipane, window)
const PageBreak = {
data() {
return {
screenWidth: document.documentElement.clientHeight,
}
},
computed: {
largeScreen () {
return this.screenWidth > 768; // 10px for handle
}
},
// bind event handlers to the `handleResize` method (defined below)
mounted: function () {
window.addEventListener('resize', this.handleResize)
},
beforeDestroy: function () {
window.removeEventListener('resize', this.handleResize)
},
methods: {
// whenever the document is resized, re-set the 'fullHeight' variable
handleResize (event) {
this.screenWidth = document.documentElement.clientWidth
}
}
}
new Vue({
el: '#app',
mixins: [ PageBreak ]
})
.custom-resizer {
width: 100%;
height: 400px;
}
.custom-resizer > .pane {
text-align: left;
padding: 15px;
overflow: hidden;
background: #eee;
border: 1px solid #ccc;
}
.custom-resizer > .multipane-resizer {
margin: 0;
left: 0;
position: relative;
}
.custom-resizer > .multipane-resizer:before {
display: block;
content: "";
width: 3px;
height: 40px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -20px;
margin-left: -1.5px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
}
.custom-resizer > .multipane-resizer:hover:before {
border-color: #999;
}
.left-pane {
width: 50%;
}
@media (max-width: 768px) {
/* stack panes if smaller than 768px*/
.multipane.layout-v {
/*flex-direction: column;*/
display: block;
}
.left-pane {
/*flex-grow: 1;*/
/* how to maximize left-pane if it was shrinked before? */
width: 100%;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.3/css/bulma.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.js"></script>
<script src="https://unpkg.com/vue-multipane@0.9.5/dist/vue-multipane.min.js"></script>
<div id="app">
<multipane class="custom-resizer" layout="vertical">
<div class="pane left-pane">
<div>
<h6 class="title is-6">Pane 1</h6>
</div>
</div>
<multipane-resizer v-if="largeScreen"></multipane-resizer>
<div class="pane" :style="{ flexGrow: 1 }">
<div>
<h6 class="title is-6">Pane 2</h6>
</div>
</div>
<!--<multipane-resizer></multipane-resizer>
<div class="pane" :style="{ flexGrow: 1 }">
<div>
<h6 class="title is-6">Pane 3</h6>
</div>
</div>-->
</multipane>
</div>
【问题讨论】:
标签: javascript css vue.js