javascript - 如何添加相当于 .mouseLeave 的触摸

标签 javascript html css

我需要帮助在下面的脚本中添加一个相当于 .mouseLeave 的触摸功能,这样悬停效果就会离开。

<figure class="snip1554">
  <img src=https://ae01.alicdn.com/kf/HTB1Jgc1bCFRMKJjy0Fhq6x.xpXao/FOCALLURE-18-Colors-Glitter-Eye-Shadow-Cosmetic-Makeup-Diamond-Lips-Loose-Makeup-Eyes-Pigment-Powder.jpg />
  <figcaption>
    <h3>Let them lose themselves in your eyes</h3>
  </figcaption>
  <a href="#"></a>
</figure>

<style>
@import url(https://fonts.googleapis.com/css?family=Poppins:700;);
.snip1554 {
  background-color: #045e78;
  color: #ffffff;
  display: inline-block;
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  margin: 0px;
  max-width: 315px;
  min-width: 230px;
  overflow: hidden;
  position: relative;
  text-align: left;
  width: 100%;
}

.snip1554 * {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-transition: all 0.45s ease;
  transition: all 0.45s ease;
}

.snip1554:after {
  background-color: white;
  opacity: 0.6;
  top: 0;
  bottom: 0;
  content: '';
  left: -100%;
  position: absolute;
  width: 100%;
  box-shadow: 0 0 100px white;
  -webkit-transform: skew(-20deg);
  transform: skew(-20deg);
  -webkit-transition: all 0.6s ease;
  transition: all 0.6s ease;
}

.snip1554 img {
  vertical-align: top;
  max-width: 100%;
  backface-visibility: hidden;
}

.snip1554 figcaption {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  line-height: 1em;
  opacity: 0;
}

.snip1554 h3 {
  position: absolute;
  left: 0px;
  bottom: 10px;
  font-size: 1em;
  font-weight: 400;
  line-height: 1.1em;
  margin: 0;
  text-transform: uppercase;
}

.snip1554 h3 span {
  font-weight: 100;
}

.snip1554 a {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
}

.snip1554:hover > img,
.snip1554.hover > img {
  opacity: 0.4;
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
}

.snip1554:hover:after,
.snip1554.hover:after {
  left: 200%;
}

.snip1554:hover figcaption,
.snip1554.hover figcaption {
  opacity: 1;
}
</style>

<script>
$(".hover").mouseleave(
  function () {
    $(this).removeClass("hover");
  }
;
  }
);

</script>

我所说的代码就在这一段上面的脚本中。我需要一些用于触摸设备的东西,以便消除悬停效果,而不仅仅是停留。

最佳答案

您可以使用touchend()(类似于mouseLeave)...

https://developer.mozilla.org/en-US/docs/Web/Events/touchend

您也可以为此添加相同的悬停类... 但是你需要先获取useragent...

if(navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|BlackBerry|Opera Mini)/)){
  $('body').on('touchend','your element', function(){
    // something to trigger transition 
  });
}

关于javascript - 如何添加相当于 .mouseLeave 的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49979564/

相关文章:

html - 尝试使用 CSS Sprites 减少 HTTP 请求,但现在图像显示不正确

javascript - 使用 View 更改调整 CSS 设计

html - CSS使div被压扁

javascript - 搜索适配的 cli 浏览器

javascript - 在 URL 中隐藏 index.html

C# 和 JS 函数的链接

javascript - 为什么 Firefox、Safari 和 Chrome 之间的滚动不一致?

javascript - 如何使用 dragover 事件从元素的所有子元素中删除指针事件?

javascript - 使用 JavaScript 解析多维数据

javascript - 函数调用本身不起作用(无限循环,Javascript)