Javascript 将覆盖添加到bootstrap 3移动导航切换后的内容

Javascript 将覆盖添加到bootstrap 3移动导航切换后的内容,javascript,jquery,css,twitter-bootstrap,Javascript,Jquery,Css,Twitter Bootstrap,我正在尝试下面的代码(在footer.php中),但没有这样的运气 脚本: $(document).ready(function(e) { $('.navbar-collapse').click(function(){ $(function() { var docHeight = $(document).height(); $("body").append("<div id='overlay'></div>"); $("#

我正在尝试下面的代码(在footer.php中),但没有这样的运气

脚本:

$(document).ready(function(e) {
    $('.navbar-collapse').click(function(){
$(function() {

    var docHeight = $(document).height();

   $("body").append("<div id='overlay'></div>");

           $("#overlay")
            .height(docHeight)
            .css({
                 'opacity' : 0.7,
                 'position': 'fixed',
                 'top': 0,
                 'left': 0,
                 'background-color': 'black',
                 'width': '100%',
                 'z-index': 5000
              });
        }); 
    });
});
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
$(文档).ready(函数(e){
$('.navbar collapse')。单击(函数(){
$(函数(){
var docHeight=$(document).height();
$(“正文”)。追加(“”);
$(“叠加”)
.身高(八)
.css({
“不透明度”:0.7,
'位置':'固定',
“顶部”:0,
“左”:0,
“背景色”:“黑色”,
“宽度”:“100%”,
“z指数”:5000
});
}); 
});
});
加价:

$(document).ready(function(e) {
    $('.navbar-collapse').click(function(){
$(function() {

    var docHeight = $(document).height();

   $("body").append("<div id='overlay'></div>");

           $("#overlay")
            .height(docHeight)
            .css({
                 'opacity' : 0.7,
                 'position': 'fixed',
                 'top': 0,
                 'left': 0,
                 'background-color': 'black',
                 'width': '100%',
                 'z-index': 5000
              });
        }); 
    });
});
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>


当导航切换被触发并出现时,关于如何淡出或灰显背景或所有主体内容的任何建议——目标是使移动导航不是不透明的,而是所有其他内容都是不透明的。为任何指点干杯。(Wordpress网站)例如,单击导航>出现导航切换>正文,其后面和其他地方的所有内容都是#000不透明度。7当导航切换存在时,一旦关闭,将恢复到原始状态而不显示不透明度。

一个好的开始是将jquery更改为以下内容:

$(function() {

  var docHeight = $(window).height();
  $('.navbar-collapse').click(function(){
     $("<div id='overlay'>")
      .height(docHeight)
      .css({
           'opacity' : 0.7,
           'position': 'fixed',
           'top': 0,
           'left': 0,
           'background-color': 'black',
           'width': '100%',
           'z-index': 5000
      }).appendTo('body');
  });
  
});
然后css

body.menu-open:after {
    content: '';
    display: block;
    position: fixed;
    top: 0; bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0,0,0,0.7);

}

一个好的开始是将jquery更改为以下内容:

$(function() {

  var docHeight = $(window).height();
  $('.navbar-collapse').click(function(){
     $("<div id='overlay'>")
      .height(docHeight)
      .css({
           'opacity' : 0.7,
           'position': 'fixed',
           'top': 0,
           'left': 0,
           'background-color': 'black',
           'width': '100%',
           'z-index': 5000
      }).appendTo('body');
  });
  
});
然后css

body.menu-open:after {
    content: '';
    display: block;
    position: fixed;
    top: 0; bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0,0,0,0.7);

}

一个好的开始是将jquery更改为以下内容:

$(function() {

  var docHeight = $(window).height();
  $('.navbar-collapse').click(function(){
     $("<div id='overlay'>")
      .height(docHeight)
      .css({
           'opacity' : 0.7,
           'position': 'fixed',
           'top': 0,
           'left': 0,
           'background-color': 'black',
           'width': '100%',
           'z-index': 5000
      }).appendTo('body');
  });
  
});
然后css

body.menu-open:after {
    content: '';
    display: block;
    position: fixed;
    top: 0; bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0,0,0,0.7);

}

一个好的开始是将jquery更改为以下内容:

$(function() {

  var docHeight = $(window).height();
  $('.navbar-collapse').click(function(){
     $("<div id='overlay'>")
      .height(docHeight)
      .css({
           'opacity' : 0.7,
           'position': 'fixed',
           'top': 0,
           'left': 0,
           'background-color': 'black',
           'width': '100%',
           'z-index': 5000
      }).appendTo('body');
  });
  
});
然后css

body.menu-open:after {
    content: '';
    display: block;
    position: fixed;
    top: 0; bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0,0,0,0.7);

}


我不确定我是否完全理解你的问题。你能用不同的方式来描述它吗,或者画出你想要每个州的样子吗?我只想在导航div切换到显示时,将所有网站内容和元素都变暗。因此,除当前导航外,其他所有内容都变暗或不透明度低于1。从现在起就这样了吗?你能把功能失调的代码放到JSFIDLE中吗?我不确定我是否完全理解你的问题。你能用不同的方式来描述它吗,或者画出你想要每个州的样子吗?我只想在导航div切换到显示时,将所有网站内容和元素都变暗。因此,除当前导航外,其他所有内容都变暗或不透明度低于1。从现在起就这样了吗?你能把功能失调的代码放到JSFIDLE中吗?我不确定我是否完全理解你的问题。你能用不同的方式来描述它吗,或者画出你想要每个州的样子吗?我只想在导航div切换到显示时,将所有网站内容和元素都变暗。因此,除当前导航外,其他所有内容都变暗或不透明度低于1。从现在起就这样了吗?你能把功能失调的代码放到JSFIDLE中吗?我不确定我是否完全理解你的问题。你能用不同的方式来描述它吗,或者画出你想要每个州的样子吗?我只想在导航div切换到显示时,将所有网站内容和元素都变暗。因此,除当前导航外,其他所有内容都变暗或不透明度低于1。这从现在开始就有意义了吗?你能把不正常的代码放到JSFIDLE中吗?谢谢你的反馈并帮助我清理我的脚本。。但是当nav出现时,这个窗台并没有使nav后面的内容变暗。(不起作用)正是我要找的。。!唯一的问题是,在我的环境中,它也影响了我的nav本身,这可能是因为body tag现在正在查看它。感谢您的反馈并帮助我清理脚本。。但是当nav出现时,这个窗台并没有使nav后面的内容变暗。(不起作用)正是我要找的。。!唯一的问题是,在我的环境中,它也影响了我的nav本身,这可能是因为body tag现在正在查看它。感谢您的反馈并帮助我清理脚本。。但是当nav出现时,这个窗台并没有使nav后面的内容变暗。(不起作用)正是我要找的。。!唯一的问题是,在我的环境中,它也影响了我的nav本身,这可能是因为body tag现在正在查看它。感谢您的反馈并帮助我清理脚本。。但是当nav出现时,这个窗台并没有使nav后面的内容变暗。(不起作用)正是我要找的。。!唯一的问题是,在我的环境中,这个实现也影响了我的导航本身,可能是因为body标签现在正在查看它。