我有一个解决方案:
将粘性/固定 div 移到“off-canvas-content”之外。
<div class="off-canvas-wrapper">
<div class="off-canvas position-left" data-off-canvas id="offCanvasL">
<!-- LEFT MENU -->
</div>
<div class="off-canvas position-right" data-off-canvas id="offCanvasR">
<!-- RIGHT MENU -->
</div>
<div class="fixed_div">
<div class="menu_left" data-toggle="offCanvasL"><!-- OPEN LEFT MENU --></div>
<div class="menu_right" data-toggle="offCanvasR"><!-- OPEN RIGHT MENU --></div>
</div>
<div class="off-canvas-content" data-off-canvas-content>
<!-- YOUR CONTENT-->
</div>
</div>
然后我们需要一些CSS规则:
.fixed_div {
position: fixed;
top: 0;
width: 100%;
z-index: 10;
transform: none;
transition: transform .5s ease;
backface-visibility: hidden;
}
.fixed_div.is-open-right.has-transition-push {
transform: translateX(-250px);
}
.fixed_div.is-open-left.has-transition-push {
transform: translateX(250px);
}
最后认为我们需要做的是在我们的app.js中添加一些JQUERY:
$('.menu_left').click(function() {
$('.fixed_div').toggleClass('is-open-right has-transition-push has-position-right');
});
$('.menu_right').click(function() {
$('.fixed_div').toggleClass('is-open-left has-transition-push has-position-left');
});
$('.close-button, .js-off-canvas-overlay').click(function() {
$('.fixed_div').removeClass('is-open-right is-open-left has-transition-push has-position-right has-position-left');
});
这就是全部:)