gpt4 book ai didi

android - 启用 :hover effect on a touch screen environment

转载 作者:太空宇宙 更新时间:2023-11-04 09:50:53 27 4
gpt4 key购买 nike

首先,这就是我要说的:jsfiddle .

当鼠标悬停在图片上时,您可以看到 4 个图标出现,同时图片被放大,.my-caption 的背景变暗。我已经在移动设备上对此进行了测试,但效果不如台式机。当我点击图像时,会在出现悬停效果的同时访问图标下方的链接。我也想让它在触摸屏设备(Android 和 iOS)上变得友好。

我的目标:

  1. 当用户点击图片时,悬停效果会被激活(图标显示、图片缩放和背景变暗)。如果用户再次点击图像或点击图像外的其他地方,悬停效果将被停用(恢复到正常状态)。
  2. 只有当用户点击图标(二次点击)时才能访问图标下方的链接。

如何使用 CSS 或简单的 JS 实现此目的?感谢您的帮助。

附言。我必须归功于Mary Lou用于这种令人敬畏的悬停效果。

最佳答案

试试这个:

HTML:

<section class="my-work-area">
<div class="my-item">
<img src="http://i.imgur.com/PAj4Ky9.jpg">
<div class="my-caption text-center">
<figure class="effect-hera">
<figcaption>
<p>
<a href="http://www.google.com" target="_blank"><i class="fa fa-moon-o"></i></a>
<a href="http://www.yahoo.com" target="_blank"><i class="fa fa-smile-o"></i></a>
<a href="http://www.apple.com" target="_blank"><i class="fa fa-star-o"></i></a>
<a href="http://www.microsoft.com" target="_blank"><i class="fa fa-sun-o"></i></a>
</p>
</figcaption>
</figure>
</div>
</div>
</section>

CSS:

.my-work-area {
width: 100%;
max-width: 420px;
height: auto;
}

.my-item {
overflow: hidden;
position: relative;
}

.my-item img {
width: 100%;
-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}

.my-item.active img,
.my-item.active img {
-webkit-transform: scale(1.2);
transform: scale(1.2);
}

.my-item.active .my-caption {
background: rgba(0, 0, 0, 0.75);
visibility: visible;
}

.my-item .my-caption {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
-webkit-transition: all 0.25s ease-in-out 0s;
transition: all 0.25s ease-in-out 0s;
visibility: hidden;
}

.my-item .my-caption figure {
position: relative;
float: left;
overflow: hidden;
width: 100%;
height: 100%;
}

.my-item .my-caption figure figcaption {
padding: 2em;
font-size: 3em;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}

.my-item .my-caption figure figcaption::before,
.my-item .my-caption figure figcaption::after {
pointer-events: none;
}

.my-item .my-caption figure figcaption,
.my-item .my-caption figure figcaption > a {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.my-item .my-caption figure figcaption > a {
z-index: 1000;
text-indent: 200%;
white-space: nowrap;
font-size: 0;
opacity: 0;
}

.my-item .my-caption figure p {
margin: 0;
letter-spacing: 2px;
font-size: 60%;
}

figure.effect-hera {
background: transparent;
}

figure.effect-hera p {
position: absolute;
top: 50%;
left: 50%;
-webkit-transition: opacity 0.35s, transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: translate3d(-50%,-50%,0);
transform: translate3d(-50%,-50%,0);
-webkit-transform-origin: 50%;
transform-origin: 50%;
}

figure.effect-hera figcaption::before {
position: absolute;
top: 50%;
left: 50%;
content: '';
opacity: 0;
-webkit-transition: opacity 0.35s, transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: translate3d(-50%,-50%,0) rotate3d(0,0,1,-45deg) scale3d(0,0,1);
transform: translate3d(-50%,-50%,0) rotate3d(0,0,1,-45deg) scale3d(0,0,1);
-webkit-transform-origin: 50%;
transform-origin: 50%;
}

figure.effect-hera p {
width: 100px;
text-transform: none;
line-height: 1.8;
}

figure.effect-hera p a {
color: linen;
}

figure.effect-hera p a:hover {
color: gold;
}

figure.effect-hera p a i {
font-size: 1.2em;
}

figure.effect-hera p a i {
opacity: 0;
-webkit-transition: opacity 0.35s, transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
}

figure.effect-hera p a:first-child i {
-webkit-transform: translate3d(-60px,-60px,0);
transform: translate3d(-60px,-60px,0);
}

figure.effect-hera p a:nth-child(2) i {
-webkit-transform: translate3d(60px,-60px,0);
transform: translate3d(60px,-60px,0);
}

figure.effect-hera p a:nth-child(3) i {
-webkit-transform: translate3d(-60px,60px,0);
transform: translate3d(-60px,60px,0);
}

figure.effect-hera p a:nth-child(4) i {
-webkit-transform: translate3d(60px,60px,0);
transform: translate3d(60px,60px,0);
}

.my-item.active figure.effect-hera figcaption::before {
opacity: 1;
-webkit-transform: translate3d(-50%,-50%,0) rotate3d(0,0,1,-45deg) scale3d(1,1,1);
transform: translate3d(-50%,-50%,0) rotate3d(0,0,1,-45deg) scale3d(1,1,1);
}

.my-item.active figure.effect-hera p i:empty {
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
opacity: 1;
}

jQuery:

$('.my-item').on('click', function() {
$('.my-item').removeClass('active');
$(this).addClass('active');
});

$(document).on("click", function(e) {
if (!($(e.target).is('.my-item') || $($(e.target).parents('.my-item')).is('.my-item'))){
$('.my-item').removeClass('active');
}
});

演示:https://jsfiddle.net/gwuuzmah/5/

关于android - 启用 :hover effect on a touch screen environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39102696/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com