【发布时间】:2022-05-05 10:40:15
【问题描述】:
我有一个带有侧面导航栏的网站,它应该通过右侧滑入,然后当您关闭它时,它会转换回侧面。在设计这个时,我意识到点击侧边栏后,它会覆盖我的“transition:0.5s”风格,而只是出现。
这是我的代码
window.onclick = function(event){if(event.target == document.getElementById('outerNav')){closeNav();}};
function openNav() {
document.getElementById("outerNav").style.display = "block";
document.getElementById("outerNav").style.transition = "0.5s";
document.getElementById("jrc-sidenav").style.width = "250px";
document.getElementById("et-main-area").style.opacity = "0.7";
document.getElementById("jrc-sidenav-background").style.backgroundColor = "rgba(255,255,255,0.7)";
document.getElementById("hamburger").style.display = "none";
}
function closeNav() {
document.getElementById("jrc-sidenav").style.width = "0";
document.getElementById("et-main-area").style.opacity = "1";
document.getElementById("jrc-sidenav-background").style.backgroundColor = "#fff";
document.getElementById("hamburger").style.display = "block";
setTimeout(function(){
document.getElementById("outerNav").style.display = "none";
},500);
}
.outerNav {
display: none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: transparent;
transition: 0.5s;
}
<div id="outerNav" class="outerNav">
<div id="jrc-sidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<form autocomplete="off" name="wpv-filter--TCPID247646" action="https://jrcstage.jr-staging.info/search-results/" method="get" class="wpv-filter-form js-wpv-filter-form js-wpv-filter-form--TCPID247646 js-wpv-form-full" data-viewnumber="-TCPID247646" data-viewid="" data-viewhash="W10=" data-viewwidgetid="0" data-orderby="" data-order="" data-orderbyas="" data-orderbysecond="" data-ordersecond="" data-parametric="{" query":"normal","id":null,"view_id":null,"widget_id":0,"view_hash":"-tcpid247646","action":"\="" test-quadmenu\="" ?wpv_view_count="-TCPID247646","sort":{"orderby":"","order":"","orderby_as":"","orderby_second":"","order_second":""},"orderby":"","order":"","orderby_as":"","orderby_second":"","order_second":"","ajax_form":"","ajax_results":"","effect":"fade","prebefore":"","before":"","after":"","attributes":[],"environment":{"current_post_id":247646,"parent_post_id":0,"parent_term_id":0,"parent_user_id":0,"archive":{"type":"","name":"","data":[]}},"loop":{"type":"","name":"","data":[],"id":0}}"" data-attributes="[]" data-environment="{" current_post_id":247646,"parent_post_id":0,"parent_term_id":0,"parent_user_id":0,"archive":{"type":"","name":"","data":[]}}"=""><input type="hidden" class="js-wpv-dps-filter-data js-wpv-filter-data-for-this-form" data-action="https://jrcstage.jr-staging.info/search-results/" data-page="1" data-ajax="disable" data-effect="fade" data-maxpages="1" data-ajaxprebefore="" data-ajaxbefore="" data-ajaxafter=""><input class="wpv_view_count wpv_view_count--TCPID247646" type="hidden" name="wpv_view_count" value="-TCPID247646">
<div class="form-group search-page search">
<div class="search-form-group-inner">
<input type="text" name="wpv_post_search" class="js-wpv-filter-trigger-delayed filter-text-search form-control" placeholder="Search"><i class="fas fa-search" style="position: absolute;
right: 20px;
top: 54px;
color: #aaaa;"></i>
<span style="display:none" class="js-wpv-dps-spinner"><img src="https://jrcstage.jr-staging.info/wp-content/plugins/wp-views/embedded/res/img/ajax-loader4.gif"></span>
<input type="submit" class="jrc-search-button wpv-submit-trigger js-wpv-submit-trigger btn" name="wpv_filter_submit" value="Search">
</div>
</div>
</form>
【问题讨论】:
标签: javascript html css css-transitions nav