点击时通知栏不会解雇

时间:2017-11-06 23:19:47

标签: javascript jquery css css3

尝试在页面的页脚创建隐私政策通知栏,仅显示新访问者。希望关闭点击接受的通知。现在,条形图显示在页面底部,但我似乎无法点击通知栏。

<span class="banner tracking-banner p-t-1">
<div class="container">
<div class="row">
  <div class="col-sm-10 text-left m-b-1">
    This website uses cookies and other 3rd party services to customize and provide you a more personalized experience. To find out more, see our <a href="/privacy/">Privacy Policy</a>.
  </div>
  <div class="col-sm-2 m-b-1">
    <button class="dismiss btn btn-sm btn-block btn-invert">Accept</button>
  </div>
</div>
</div>
</span>

JS

$(".banner").fadeIn("slow").append(".container");
$(".dismiss").click(function(){
   $(".banner").fadeOut("slow");
});

2 个答案:

答案 0 :(得分:3)

将您的代码包装在文档就绪函数

$(document).ready(function(){

$(".banner").fadeIn("slow").append(".container");
$(".dismiss").click(function(){
   $(".banner").fadeOut("slow");
});
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<span class="banner tracking-banner p-t-1">
<div class="container">
<div class="row">
  <div class="col-sm-10 text-left m-b-1">
    This website uses cookies and other 3rd party services to customize and provide you a more personalized experience. To find out more, see our <a href="/privacy/">Privacy Policy</a>.
  </div>
  <div class="col-sm-2 m-b-1">
    <button class="dismiss btn btn-sm btn-block btn-invert">Accept</button>
  </div>
</div>
</div>
</span>

答案 1 :(得分:0)

将您的范围更改为div?让你的fadeOut工作。

<div class="banner tracking-banner p-t-1">
<div class="container">
<div class="row">
  <div class="col-sm-10 text-left m-b-1">
    This website uses cookies and other 3rd party services to customize and provide you a more personalized experience. To find out more, see our <a href="/privacy/">Privacy Policy</a>.</div>
  <div class="col-sm-2 m-b-1">
    <button class="dismiss btn btn-sm btn-block btn-invert">Accept</button>
  </div>
</div>
</div>
</div>