开发者问题收集

Bootstrap 模式奇怪的问题

2016-08-30
93

我有一些使用 CSS3 制作的动画元素。块内有一个可打开模态窗口的链接,但当模态窗口关闭时,动画元素将保持“悬停”状态。

jsfiddle 中的示例:

<style>
    .item-wrap {
  position: relative;
  height: 200px;
  width: 200px;
  background-color: black;
  overflow: hidden;
}
.item-wrap p {
  color: #fff;
  text-align: center;
}
.item-wrap::before {
  content: ' ';
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 100%;
  opacity: 0.5;
  -webkit-transition: width 0s ease, background-color 0.5s ease;
  -moz-transition: width 0s ease, background-color 0.5s ease;
  -o-transition: width 0s ease, background-color 0.5s ease;
  transition: width 0s ease, background-color 0.5s ease;
}
.item-wrap::after {
  content: ' ';
  position: absolute;
  right: 0;
  top: 0;
  width: 0;
  height: 100%;
  opacity: 0.5;
  background-color: #fff;
  transition: width 0.5s ease;
  -webkit-transition: width 0.5s ease;
  -moz-transition: width 0.5s ease;
  -ms-transition: width 0.5s ease;
  -o-transition: width 0.5s ease;
}

.item-wrap:hover::before {
  width: 100%;
  background-color: #fff;
  transition: width 0.5s ease;
  -webkit-transition: width 0.5s ease;
  -moz-transition: width 0.5s ease;
  -ms-transition: width 0.5s ease;
  -o-transition: width 0.5s ease;
}
.item-wrap:hover::after {
  width: 100%;
  background-color: transparent;
  transition: all 0s ease;
  -webkit-transition: all 0s ease;
  -moz-transition: all 0s ease;
  -ms-transition: all 0s ease;
  -o-transition: all 0s ease;
}
.item-wrap:hover .cover {
  bottom: 0;
}
.cover a {
  color: #fff;
}
.link1 {
  position: absolute;
  left: 20px;
  top: 50%;
  right: 20px;
}
.link2 {
  position: absolute;
  top: 50%;
  right: 20px;
} 
.item-wrap .cover {
  position: absolute;
  right: 0;
  left: 0;
  bottom: -100%;
  width: 100%;
  height: 100%;
  transition: bottom 0.3s linear;
  -webkit-transition: bottom 0.3s linear;
  -moz-transition: bottom 0.3s linear;
  -ms-transition: bottom 0.3s linear;
  -o-transition: bottom 0.3s linear;
  z-index: 10;
}
</style>
    <div class="item">
      <div class="item-wrap">
       <p>Main content blah blah</p>
        <div class="cover">
          <a href="#" class="link1" data-toggle="modal" data-target="#myModal">Link1</a>
          <a href="#" class="link2" data-toggle="modal" data-target="#myModal">Link2</a>
       </div><!-- /.cover -->
     </div><!-- /.item-wrap -->
   </div><!-- /.item -->

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

jsfiddle 中的示例: https://jsfiddle.net/9objpv9x/

尝试悬停以查看动画和模态链接,然后单击“Link1”并关闭模态以查看接下来会发生什么。

我只是不知道从哪里开始挖掘。

1个回答

实际上,“link1”处于“焦点”状态,并且由于默认的 bootstrap css 属性而显示轮廓:

a:focus {
   outline: 5px auto -webkit-focus-ring-color;
   outline-offset: -2px;
}

要覆盖它,请在您的 css 中对其进行修改。

a#id:focus {
   outline: 0px;
}

要在模式关闭后删除焦点状态, 我们需要在 jquery 中触发模式,而不是在 HTML 中使用“data-target”。

查看此 jsfiddle 链接。 更新的代码修复

2016-08-30