CSS转换不透明度在手机上不起作用

问题描述 投票:0回答:1

我正在使用此站点上的代码:https://codepen.io/tutsplus/pen/rQrVBg用触摸或移过的乳清结构制作一个图像网格,其中会显示一些文本。在PC上过渡效果很好,但是当我在手机上进行测试时,图片上出现了不透明的颜色。我在Safari,Chrome和Edge中进行了测试,但均无法正常工作。

body {
  padding: 20px;
  font-family: sans-serif;
  background: #f2f2f2;
}

img {
  width: 100%;
  /* need to overwrite inline dimensions */
  height: auto;
}

h2 {
  margin-bottom: .5em;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  grid-gap: 1em;
}


/* hover styles */

.location-listing {
  position: relative;
}

.location-image {
  line-height: 0;
  overflow: hidden;
}

.location-image img {
  filter: blur(0px);
  transition: filter 0.3s ease-in;
  transform: scale(1.1);
}

.location-title {
  font-size: 1.5em;
  font-weight: bold;
  text-decoration: none;
  z-index: 1;
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  opacity: 0;
  transition: opacity .5s;
  background: rgba(90, 0, 10, 0.4);
  color: white;
  /* position the text in t’ middle*/
  display: flex;
  align-items: center;
  justify-content: center;
}

.location-listing:hover .location-title {
  opacity: 1;
}

.location-listing:hover .location-image img {
  filter: blur(2px);
}


/* for touch screen devices */

@media (hover: none) {
  .location-title {
    opacity: 1;
  }
  .location-image img {
    filter: blur(2px);
  }
}
<div class="child-page-listing">

  <h2>Our Locations</h2>

  <div class="grid-container">

    <article id="3685" class="location-listing">

      <a class="location-title" href="#">
        San Francisco						
      </a>

      <div class="location-image">
        <a href="#">
          <img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
        </a>

      </div>

    </article>

    <article id="3688" class="location-listing">

      <a class="location-title" href="#">
        London						
      </a>

      <div class="location-image">
        <a href="#">
          <img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/london-768x432.jpg" alt="london">
        </a>

      </div>

    </article>

    <article id="3691" class="location-listing">

      <a class="location-title" href="#">
        New York						
      </a>

      <div class="location-image">
        <a href="#">
          <img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/new-york-768x432.jpg" alt="new york">
        </a>

      </div>

    </article>

    <article id="3694" class="location-listing">

      <a class="location-title" href="#">
        Cape Town						
      </a>

      <div class="location-image">
        <a href="#">
          <img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/cape-town-768x432.jpg" alt="cape town">
        </a>

      </div>

    </article>

    <article id="3697" class="location-listing">

      <a class="location-title" href="#">
        Beijing						
      </a>

      <div class="location-image">
        <a href="#">
          <img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/beijing-768x432.jpg" alt="beijing">
        </a>

      </div>

    </article>

    <article id="3700" class="location-listing">

      <a class="location-title" href="#">
        Paris
      </a>

      <div class="location-image">
        <a href="#">
          <img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/paris-768x432.jpg" alt="paris">
        </a>
      </div>

    </article>

  </div>
  <!-- end grid container -->

</div>
css transition opacity codepen
1个回答
0
投票

由于移动浏览器中没有悬停效果(没有鼠标光标移动/悬停在图像上,所以在移动/触摸屏设备上无法获得相同的行为。

CSS末尾的媒体查询正在对所有'.location-title'元素应用样式,并对所有'.location-image img'元素应用模糊处理。无论用户是否与这些元素进行交互,这些效果都将应用于这些效果。我会在此示例中说,如果浏览器没有悬停功能,则使用@media查询将样式分配给元素,这是可以接受的后备行为。如果您想要更类似于移动设备上的桌面行为(例如,将CSS规则应用于触摸事件中的活动元素),则您的特定解决方案可能需要使用不同的方法。

© www.soinside.com 2019 - 2024. All rights reserved.