我在页面底部有这个用于面板显示/隐藏的 jQuery。 但是面板在页面加载时弹出。我需要在页面加载时隐藏面板,并且需要在切换时显示它。
这是我的 JS:
(function($) {
jQuery(document).ready(function() {
Panel.init();
$(document).on('click', '.tab-controller', function() {
Panel.togglePanel();
});
});
var Panel = {
isVisible : true,
showMessage : null,
hideMessage : null,
animationDuration : 650,
animationEasing : 'linear',
init : function() {
},
hidePanel : function() {
$('.panel-wrapper').animate({
bottom : -(Panel.getAnimationOffset())
}, Panel.animationDuration, Panel.animationEasing, function() {
Panel.isVisible = false;
Panel.updateTabMessage();
});
},
showPanel : function() {
$('.panel-wrapper').animate({
bottom : 0
}, Panel.animationDuration, Panel.animationEasing, function() {
Panel.isVisible = true;
Panel.updateTabMessage();
});
},
togglePanel : function() {
((this.isVisible) ? this.hidePanel : this.showPanel)();
},
updateTabMessage : function() {
if (this.isVisible) {
$('.tab-controller .close').show();
$('.tab-controller .show').hide();
} else {
$('.tab-controller .close').hide();
$('.tab-controller .show').show();
}
},
getAnimationOffset : function() {
return $('.panel-content').height();
}
}
})(jQuery);
我试过 isVisible=false 没有用。所以我在 init 函数中调用 hidePanel 它现在工作正常,但问题是面板现在在页面加载时隐藏动画。我根本不想在页面加载时显示面板
这是我的 CSS:
.panel-wrapper * {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.panel-wrapper {
position: fixed;
left: 0;
bottom: 0;
overflow: hidden;
width: 100%;
font-family: sans-serif;
}
.panel-controller {
position: relative;
overflow: hidden;
width: 100%;
}
.tab-controller {
float: right;
margin-right: 50px;
padding: 10px 10px 5px;
background-color: #8C293B;
-webkit-border-radius: 15px 15px 0 0;
-moz-border-radius: 15px 15px 0 0;
border-radius: 15px 15px 0 0;
}
.tab-controller * {
display: block;
font-family: sans-serif;
font-size: 16px;
font-weight: bold;
color: white;
cursor: pointer;
}
.tab-controller .show {
display: none;
}
.panel-content {
overflow: hidden;
width: 100%;
background-color: #8C293B;
}
这是我的 HTML:
<div class="panel-wrapper">
<div class="panel-controller">
<div class="tab-controller"> <span class="close">CLOSE PANEL</span> <span class="show">OPEN PANEL</span> </div>
</div>
<div class="panel-content">
Panel content goes here
</div>
</div>
最佳答案
您可以将您的 isVisible 字段默认设置为 false,但如果您想保持这样,您应该在您的 init 中调用您的 hidePanel
关于javascript - 在页面加载时,底部面板应该隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36103625/