【问题标题】:Boostrap modal strange issueBootstrap 模态奇怪的问题
【发布时间】:2016-08-30 22:18:57
【问题描述】:

我有一些用 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”并关闭模态以查看接下来会发生什么。

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

【问题讨论】:

    标签: javascript twitter-bootstrap css bootstrap-modal


    【解决方案1】:

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

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

    要覆盖它,请在您的 css 中修改它。

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

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

    查看这个 jsfiddle 链接。 Updated Code Fix

    【讨论】:

    • 使用这个,如果只有元素的大纲是问题。当模式关闭时,否则会触发页面中任何其他元素的焦点。
    • 但是问题依然存在,问题是modal close后的'.cover'元素定位在最上面,但必须在外面。
    • Check this jsfiddle link 问题是 HTML 的默认行为,并且引导程序在模式隐藏后返回相同的链接以成为焦点。所以为了消除它,我删除了 HTML 中的 data-target 并触发了 jquery 中的模式。但是,我不确定这是不是正确的消除方法。
    • 嗯,这很有趣,所以如果问题出在焦点上,是不是可以在模态“显示”事件上通过 blur() 用 jquery 移除焦点?
    • 我试过了。但是,它不起作用。数据目标捕获页面的当前状态,并最终在模式关闭后返回它们。我什至在模态关闭事件之后尝试过。它不起作用。
    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多