javascript - 在页面加载时,底部面板应该隐藏

标签 javascript jquery html css

我在页面底部有这个用于面板显示/隐藏的 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/

相关文章:

javascript - 停止检查 alpineJS 中的复选框?

jquery - 使用 JQuery 在悬停时用 div 包裹图像

jquery - 同位素 : How to display and set opacity values for unmatched items

html - 登录屏幕想要在同一行

html - 如何围绕子 div 自动调整父 div?

javascript - AngularJS - 添加数据时 ng-repeat 不更新

javascript - Express.js CRUD 应用程序错误 : update function does wrong redirect

javascript - 使用 Javascript 和 JQuery 对 svg 元素进行动画处理

javascript - Twitter Bootstrap 顶部菜单未知组件向下滑动

jquery - Materialise - DropDown onclick 消失问题