【问题标题】:Keeping the expanded box open when a video is played播放视频时保持展开的框打开
【发布时间】:2016-07-16 17:00:40
【问题描述】:

我有一个图像地图,其中有多个点,单击时会放大到方框中。当您在框外单击时,放大的框会关闭回到原来的位置。

看到这个fiddle

不幸的是,当我使用 IFrame 嵌入视频并在视频上单击播放时,它会关闭放大的框,就像我在框外单击一样。

我相信这是因为它将焦点从 .mappoint 移开并将其带到 IFrame。

我目前的系统只使用 HTML 和 CSS,但我很乐意扩展,我只是对 jQuery 等知之甚少。

我卡住了,我希望放大的框在播放和暂停视频时保持放大。你们知道我的问题的解决方案吗?

html 
  color: #e5e5e5;
  text-align: center;
  font-family: "Roboto", Helvetica, sans-serif;
}

body {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 100px;
  overflow-x: hidden;
}

.description {
  max-width: 600px;
  margin: 0 auto;
  color: rgba(229, 229, 229, 0.7);
}

div,
img,
footer {
  position: relative;
  box-sizing: border-box;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-bottom: 20px;
  text-transform: uppercase;
  font-family: "Roboto Condensed", Helvetica, sans-serif;
  font-weight: 300;
}

h1 {
  font-size: 36pt;
}

h2 {
  font-size: 24pt;
}

h3 {
  font-size: 18pt;
}

h4 {
  font-size: 16pt;
}

h5 {
  font-size: 14pt;
}

h6 {
  font-size: 12pt;
}

p {
  font-size: 12pt;
  margin-bottom: 12pt;
  margin-right: 12px;
  margin-left: 12px;
}

strong {
  font-weight: 900;
  font-family: "Roboto Condensed", Helvetica, sans-serif;
  color: #e5e5e5;
}

a {
  -webkit-transition: color 0.25s ease-in-out;
  transition: color 0.25s ease-in-out;
  font-family: "Roboto Condensed", Helvetica, sans-serif;
  text-transform: uppercase;
  text-decoration: none;
  color: #dff3fd;
}

a:visited {
  color: #dff3fd;
}

li.active a,
a:hover,
a:active {
  color: #e5e5e5;
}

.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -50px;
  margin-left: -100px;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.centered-y {
  position: inline-block;
  width: auto;
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}

.distribution-map {
  position: relative;
  width: 1190px;
  padding: 20px;
  box-sizing: border-box;
  margin: 0 auto;
}

.distribution-map > img {
  width: 100%;
  position: relative;
  margin: 0;
  padding: 0;
}

.distribution-map .map-point {
  cursor: pointer;
  outline: none;
  z-index: 0;
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  filter: progid: DXImageTransform.Microsoft.Alpha(Opacity=80);
  opacity: 0.8;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  -moz-transition: opacity 0.25s ease-in-out 0.25s, width 0.25s ease-in-out 0.25s, height 0.25s ease-in-out 0.25s, z-index 0.25s ease-in-out 0.25s;
  -o-transition: opacity 0.25s ease-in-out 0.25s, width 0.25s ease-in-out 0.25s, height 0.25s ease-in-out 0.25s, z-index 0.25s ease-in-out 0.25s;
  -webkit-transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out, z-index 0.25s ease-in-out;
  -webkit-transition-delay: 0.25s, 0.25s, 0.25s, 0.25s;
  -webkit-transition: opacity 0.25s ease-in-out 0.25s, width 0.25s ease-in-out 0.25s, height 0.25s ease-in-out 0.25s, z-index 0.25s ease-in-out 0.25s;
  transition: opacity 0.25s ease-in-out 0.25s, width 0.25s ease-in-out 0.25s, height 0.25s ease-in-out 0.25s, z-index 0.25s ease-in-out 0.25s;
  background: rgba(26, 26, 26, 0.85);
  border: 3px solid #dff3fd;
}

.distribution-map .map-point .content {
  filter: progid: DXImageTransform.Microsoft.Alpha(Opacity=0);
  opacity: 0;
  -webkit-transition: opacity 0.25s ease-in-out;
  transition: opacity 0.25s ease-in-out;
  width: 100%;
  height: 100%;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  overflow: overlay;
}

.distribution-map .map-point:active,
.distribution-map .map-point:focus {
  position: absolute;
  margin-left: auto;
  margin-right: auto;
  padding: 0;
  filter: progid: DXImageTransform.Microsoft.Alpha(enabled=false);
  opacity: 1;
  width: 550px;
  height: 400px;
  color: #e5e5e5;
  z-index: 1;
  -webkit-transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
  transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
}

.distribution-map .map-point:active .content,
.distribution-map .map-point:focus .content {
  filter: progid: DXImageTransform.Microsoft.Alpha(enabled=false);
  opacity: 1;
  -moz-transition: opacity 0.25s ease-in-out 0.25s, height 0.25s ease-in-out, overflow 0.25s ease-in-out;
  -o-transition: opacity 0.25s ease-in-out 0.25s, height 0.25s ease-in-out, overflow 0.25s ease-in-out;
  -webkit-transition: opacity 0.25s ease-in-out, height 0.25s ease-in-out, overflow 0.25s ease-in-out;
  -webkit-transition-delay: 0.25s, 0s, 0s;
  -webkit-transition: opacity 0.25s ease-in-out 0.25s, height 0.25s ease-in-out, overflow 0.25s ease-in-out;
  transition: opacity 0.25s ease-in-out 0.25s, height 0.25s ease-in-out, overflow 0.25s ease-in-out;
  overflow: hidden;
}

.distribution-map .map-point:active .content a:hover,
.distribution-map .map-point:active .content a:active,
.distribution-map .map-point:focus .content a:hover,
.distribution-map .map-point:focus .content a:active {
  color: #dff3fd;
}
<body>
  <h1></h1>
  <div class="distribution-map">


    <button class="map-point" style="top:24%;left:26.5%">
      <div class="content">
        <div class="centered-y">
          <h2>Another</h2>
          <p>details</p>
          <iframe width="350" height="197" src="https://www.youtube.com/embed/5MgBikgcWnY" frameborder="0" allowfullscreen></iframe>
        </div>
      </div>
    </button>
    <button class="map-point" style="top:26%;left:49%">
      <div class="content">
        <div class="centered-y">
          <h2>Another</h2>
          <p>Details...</p>
        </div>
      </div>
    </button>
    <button class="map-point" style="top:27.3%;left:71.4%">
      <div class="content">
        <div class="centered-y">
          <h2>Another</h2>
          <p>Details...</p>
        </div>
      </div>
    </button>
    <button class="map-point" style="top:63.5%;left:31.5%">
      <div class="content">
        <div class="centered-y">
          <h2>Another one</h2>
          <p>Details...</p>
        </div>
      </div>
    </button>
    <button class="map-point" style="top:65%;left:56%">
      <div class="content">
        <div class="centered-y">
          <h2>another one</h2>
          <p>Details...</p>
        </div>
      </div>
    </button>
    <button class="map-point" style="top:68%;left:74%">
      <div class="content">
        <div class="centered-y">
          <h2>Another</h2>
          <p>Details...</p>
        </div>
      </div>
    </button>
  </div>

任何帮助将不胜感激,干杯。

【问题讨论】:

    标签: jquery html css iframe


    【解决方案1】:

    在尝试修复您的 JSFiddle 时,我从这个问题中询问了解决方案:

    Is it possible to focus on a div using javascript focus function - Stack Overflow

    作为参考,我将介绍我在你的小提琴上尝试过的所有内容:

    • 我尝试在您的 iframe,这样map-point 按钮仍将保持其焦点, 因此保留其 CSS :focus 选择器。
    • 除上述内容外,我还尝试将tabindex="0" 添加到您的map-point 按钮,根据上面链接中投票最高的答案。不幸的是,iframe 的焦点超过了 tabindex
    • 我尝试使用下一个最高投票答案中的document.getElementById('bad-map-point').scrollIntoView(),但没有成功。
    • 我尝试在小提琴中使用 .manualfocus 类名和丑陋的 JS,但我把 CSS 搞砸了,而不是修复它,所以我恢复了它。

    然后,我找到了一个漂亮、整洁、有效的解决方案!

    • 我在您的地图点上添加了hover 选择器,它适用于 iframe!

    变化:

    .distribution-map .map-point:active,
    .distribution-map .map-point:focus,
    .distribution-map .map-point:hover { //Added :hover
    
      ...
    }
    

    还有:

    .distribution-map .map-point:active .content,
    .distribution-map .map-point:focus .content,
    .distribution-map .map-point:hover .content { //Added :hover
    
      ...
    }
    

    它很优雅,运行流畅,而且没有 JavaScript!

    希望这会有所帮助!

    【讨论】:

    • 这很有帮助!非常感谢亚伦!它现在可以与 iframe 一起使用,并且使用悬停功能看起来也更好哈哈!感谢您的辛勤工作,我永远不会想到添加悬停!干杯:D
    猜你喜欢
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    相关资源
    最近更新 更多